This seems like it should be simple, but I'm stuck. I'm looping over a list of photo file paths from a text file and deleting each one. The problem is that if the del command fails (this could happen if the file didn't exist or was in use by some other program), I don't get any notification in the log.
BTW- This is windows server 2008 R1 CMD.
Here is my code:
@echo off for /F %%A in (f:\deletePhotos\deletelist.txt) do ( echo del %%A /f >> f:\deletePhotos\log.txt 2>&1 ) Here is a sample of the log:
del f:\photos\11\48\ALX10-9322-48.jpg /f del f:\photos\11\48\ALX10-9692-48.jpg /f del f:\photos\11\48\LKSR20-5910-48.jpg /f del f:\photos\11\48\LKSR20-8639-48.jpg /f del f:\photos\11\48\SEMN4030836-48.jpg /f del f:\photos\11\48\SEMN4036515-48.jpg /f The files from the log (above) do NOT exist (I checked). Obviously, I am trying to get the log to show some error like:
Could Not Find f:\photos\11\48\ALX10-9322-48.jpg But instead I just get an echo of the command itself. Please help!
*UPDATE* Figured it out: Good old trial and error: had to move the log output and the redirection outside of the bat file execution.
Like this:
f:\deletephotos>del.bat f:\deletePhotos\delete_11.txt >> f:\deletePhotos\log.txt 2>&1 That did the trick.