0

Yes, I did see: Delete duplicate files with Windows batch file

But I was unable to modify it to check each subfolder of that I specify, I have:

del "c:\...\Pictures\*\*-001.*"

But it doesn't like it. I only need to go one folder deep (each subfolder is a month) and I don't need to check the Pictures\ root.

I've tried this:

FOR %%F IN ("C:\...\Pictures\") DO FOR %%f IN ("C:\...\Pictures\%%F\*-001.JPG") del "%%f"

But that still isn't correct. Can anyone lend me a hand? I've very limited experience in batch files.

3
  • The question, as above, is how can I modify that line to delete duplicate files in every subfolder of `Pictures`, not just 'loose' files in that folder itself. – OJFord Jul 3 '13 at 17:55
  • That now odd looking comment above was in response to someone asking "what is the question". – OJFord Jul 5 '13 at 18:16
  • Why can't you just use windows search in Pictures to search for *001? Or del *-001.jpg /s – RJFalconer Aug 8 '14 at 16:02
1

Set your real %startfolder% and look at the output. If it is good, remove echo before del:

@echo off &SETLOCAL
SET "startfolder=."

FOR /r "%startfolder%" %%i IN (*) DO call:doit "%%~i"
goto:eof

:doit
SET "fname=%~nx1"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "fsize=!$%fname%!"
IF DEFINED $!fname! (
     ENDLOCAL
     IF "%fsize%"=="%~z1" ECHO DEL "%~1"
) ELSE (
     ENDLOCAL
     SET "$%~nx1=%~z1"
)
goto:eof

The code doesn't delete if filesizes are different.

4
  • Thanks for response - output not correct though. I don't fully understand your code, but nowhere does it look for -001 in the filename, it's those I want to remove. There's not many, they're just spread out, so I can forego a filesize check. Just delete anything ending -001.JPG. – OJFord Jul 6 '13 at 14:56
  • You can change the code: FOR /r "%startfolder%" %%i IN (*-001.jpg) DO call:doit "%%~i" to get only JPG's. And sorry, this is my last visit here. The board told me for log in I have to disable my AdBlock. But I don't do that. You can put a new question at stackoverflow, if you want so. – Endoro Jul 6 '13 at 15:12
  • Still not correct. Thanks for the help - I just went through manually in Picasa. You spend that long on trying to script it.. you may as well just be manual about it! – OJFord Jul 7 '13 at 0:21
  • @Endoro I have adblock enabled with most draconian settings and still can browse SU fine. Perhaps worthy of a question on meta – RJFalconer Aug 8 '14 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.