8

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.

1 Answer 1

8

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)

2
  • This worked perfectly - I wish I could vote twice. Thanks a lot.
    – ajcw
    Oct 3, 2012 at 11:49
  • 1
    Also works if you want to delete files from A that EXIST in B: for %F in ("A\*.gif") do @if exist "B\%~nF.jpg" echo del "%F" Nov 10, 2015 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .