So i want a batch that delete files if they exist in another folder.
delete file/s from "desktop" if the files exist in "f:/lnkremove"
Big thanks if somone can help!
Delete files if exist in a diffrent one
Moderator: DosItHelp
Re: Delete files if exist in a diffrent one
remove the word ECHO if you are satisfied with the results it outputs to the screen.
Code: Select all
@echo off
for %%G in ("f:\lnkremove\*") do IF EXIST "%userprofile%\Desktop\%%~nxG" ECHO del "%userprofile%\Desktop\%%~nxG"
Re: Delete files if exist in a diffrent one
Tankyou so much for this fast answer. Have waited stackoverflow for this
Tanks again!
Tanks again!
Re: Delete files if exist in a diffrent one
Squashman wrote:remove the word ECHO if you are satisfied with the results it outputs to the screen.Code: Select all
@echo off
for %%G in ("f:\lnkremove\*") do IF EXIST "%userprofile%\Desktop\%%~nxG" ECHO del "%userprofile%\Desktop\%%~nxG"
I have tested this now. but cant get it to work.
Code: Select all
for %%G in ("%~d0\cleanuptool\lnk\*") do IF EXIST "%userprofile%\Desktop\%%~nxG" ECHO del "%userprofile%\Desktop\%%~nxG"
And get this message:
F:\Cleanuptool>for %G in ("F:\cleanuptool\lnk\*") do IF EXIST "C:\Users\Bruker\D
esktop\%~nxG" ECHO del "C:\Users\Bruker\Desktop\%~nxG"
F:\Cleanuptool>IF EXIST "C:\Users\Bruker\Desktop\Elkjøp Cloud.lnk" ECHO del "C:\
Users\Bruker\Desktop\Elkjøp Cloud.lnk"
del "C:\Users\Bruker\Desktop\Elkjøp Cloud.lnk"
F:\Cleanuptool>IF EXIST "C:\Users\Bruker\Desktop\Steam.lnk" ECHO del "C:\Users\B
ruker\Desktop\Steam.lnk"
F:\Cleanuptool>IF EXIST "C:\Users\Bruker\Desktop\LibreOffice 4.3.lnk" ECHO del "
C:\Users\Bruker\Desktop\LibreOffice 4.3.lnk"
F:\Cleanuptool>pause
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Delete files if exist in a diffrent one
stanian wrote:F:\Cleanuptool>IF EXIST "C:\Users\Bruker\Desktop\Elkjøp Cloud.lnk" ECHO del "C:\
Users\Bruker\Desktop\Elkjøp Cloud.lnk"
del "C:\Users\Bruker\Desktop\Elkjøp Cloud.lnk"
The second line indicates that the file C:\Users\Bruker\Desktop\Elkjøp Cloud.lnk was deleted.
Re: Delete files if exist in a diffrent one
Even though it has been mentioned, the file(s) will not actually be deleted until you are happy with the script and then remove ECHO