views:

738

answers:

1

I'm working on a batch script that will let me delete files older then a set period using forfiles. For now, I'm aiming at printing the files that will be deleted.

The forfiles invocation I'm using works flawlessly from a cmd.exe shell, but as soon as I embed it into a batch script, it barfs. I suspect that this is due to the @ character not being escaped properly, but I'm not certain.

The command I'm running is:

forfiles /S /P "r:\" /m *.bak /d -10 /c "cmd /c echo @PATH"

And it results in the following error:

ERROR: Invalid argument/option - '@PATH'
Type "FORFILES /?" for usage.

I've googled all over the place and tried a few different schemes for escaping the @PATH component. Everything from @@PATH, to \"@PATH\" with no results.

Any help would be appreciated!

EDIT: I should also note that I'm basing a lot of my knowledge of forfiles from here.

+1  A: 

I had the same problem until I removed the quotation marks around the directory path , like this:

forfiles /S /P r:\ /m *.bak /d -10 /c "cmd /c echo @PATH"

Hope that helps.

DaveParsons
Removing the quotes worked!Thanks a lot!It seems incredibly strange to me that putting quotes around a file path (a standard procedure) would break a separate argument to the command in such a non-obvious way.
Paradox
Yes, its rather bizarre, but I've had the same problem just now. Nice solution. :)
jsight