Page 1 of 1
Delete files if exist in a diffrent one
Posted: 22 Oct 2014 13:17
by stanian
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!
Re: Delete files if exist in a diffrent one
Posted: 22 Oct 2014 13:47
by Squashman
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
Posted: 22 Oct 2014 13:59
by stanian
Tankyou so much for this fast answer. Have waited stackoverflow for this
Tanks again!
Re: Delete files if exist in a diffrent one
Posted: 25 Oct 2014 09:26
by stanian
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
Re: Delete files if exist in a diffrent one
Posted: 25 Oct 2014 10:58
by ShadowThief
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
Posted: 25 Oct 2014 15:10
by Compo
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