Friday, 15 September 2017

windows 7 - Delete files from one folder if a similarly named file does not exist in another folder


I need to delete files from folder A if a file with the same name but different file type does not exist in folder B.


For example:


FOLDER A
file1.gif
file2.gif
file3.gif
file4.gif
file5.gif
file6.gif

FOLDER B
file2.jpg
file4.jpg
file6.jpg

The batch file or software would compare the two folders and delete file1.gif, file3.gif and file5.gif from folder A.



Answer



You can do this directly from command line:
for %F in ("A\*.gif") do @if not exist "B\%~nF.jpg" echo del "%F"
Above example simply prints the commands so you can verify it will does what you want. After you're sure it's ok remove echo and it will actually run delete.
You may of course put this in a batch, if you wish so replace % with %% and remove @ (and probably add @echo off instead)


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...