Forfiles Batch Script (Escaping @ character)
batch-file, forfiles
Solution
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.
Problem
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! I should also note that I'm basing a lot of my knowledge of forfiles from here.