I have a scenario:
FORFILES /P "C:\users\DominiqueGerry\Work Files\" /S /M *.doc /C "cmd /c echo @fsize"
gives me an error:
ERROR: Invalid argument/option - '@fsize'.
Type "FORFILES /?" for usage.
But when I remove the slash, it works:
FORFILES /P "C:\users\DominiqueGerry\Work Files" /S /M *.doc /C "cmd /c echo @fsize"
I do not understand why this does not work without the backslash, but does not with it. I cannot find any official documentation explaining this. and do not even see any of it mentioned when running help forfiles /?
I would appreciate any help on this.
The best part is. The error is not even related to the issue at hand.
To be honest, I do not think it is documented anywhere in the official help (at least not what I have seen), but what actually happens is that the trailing backslash is actually escaping the last double quote. In my mind, this is actually a bug.
The reason why the error is not related is simply because the forfiles
command detects an error in the format, due to the missing double quote, which the backslash escaped.
You will see that this does not happen when you do not have the double quotes, so let's assume you have no space in your path:
FORFILES /P C:\users\DominiqueGerry\WorkFiles\ /S /M *.doc /C "cmd /c echo @fsize"
Would not give you an error, simply because the baskslash does not have any valid character to escape, problem is, you do have a space in path, so you must use double quotes. So it is best to retain the double quotes and not add the trailing backslash:
FORFILES /P "C:\users\DominiqueGerry\Work Files" /S /M *.doc /C "cmd /c echo @fsize"
Or if you are adamant on using the backslash, simply escape it by doubling up.
FORFILES /P "C:\users\DominiqueGerry\Work Files\\" /S /M *.doc /C "cmd /c echo @fsize"
Edit, also as mentioned in comments by @aschipfl you can use .
:
FORFILES /P "C:\users\DominiqueGerry\Work Files\." /S /M *.doc /C "cmd /c echo @fsize"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With