user3443466
user3443466

Reputation: 3

Why won't my command work in .bat file?

So my goal is to move a certain file type to one folder. Then in that folder find all the duplicates and delete them.

I came up with this:

for /r C:\users\ %%f in (*.jpg) do @copy "%%f" C:\test\ /y 
c:\tools\sfk sel -dir c:\test\ -file .jpg +dup +del!

The first part works, it moves all .jpg to a "test" folder but it then doesn't do the second part. The second part was made using SFK, it finds duplicates and deletes them in the cmd prompt but not in .bat.

Upvotes: 0

Views: 85

Answers (1)

MC ND
MC ND

Reputation: 70933

You command will not work from batch file if delayed expansion is active, as the exclamation marks will get eliminated by the parser. Disable it before the sfk command

for /r C:\users\ %%f in (*.jpg) do @copy "%%f" C:\test\ /y 
setlocal disabledelayedexpansion
c:\tools\sfk sel -dir c:\test\ -file .jpg +dup +del!
endlocal

Upvotes: 1

Related Questions