Reputation: 2821
I'm trying to run a basic forfiles command, but no matter what mask I use it always simply prints the whole content of the directory. Not filtered for *.bat no "is a batch file", just a simple list off all files in C:\ I'm working on a winXPproffesional. What could be the cause?
forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"
Upvotes: 2
Views: 1521
Reputation: 77687
As a matter of fact, there's no forfiles
in Windows XP but there is one in Windows 2003 Server, with the syntax as in your question.
Windows 2000 did have the tool, but only in the form of a resource kit, which had to be downloaded separately. For some reason, the corresponding Technet article doesn't list forfiles
as part of the kit, although, as can be derived from this and this article, it must have been there initially. Maybe the guys at Microsoft decided to stop distributing the older version to avoid possible confusion with the newer one.
And yes, it seems like your forfiles
copy is the older version, which does have a slightly different syntax, as explained in this post.
Upvotes: 0
Reputation: 2821
Somehow this version uses a different syntax:
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo @file is a batch file"
works!
Upvotes: 2
Reputation: 130849
The command should work.
Maybe you have a FORFILES.BAT, FORFILES.CMD or bogus copy of FORFILES.EXE in either your current directory or another directory that happens to be in your PATH.
Try running this command from the command line to verify that the correct FORFILES.EXE is executing.
for %F in (forfiles.exe forfiles.bat forfiles.cmd) do @echo %~$path:F
If that is not the problem, then it looks to me like you have a bugged version of FORFILES.
Try using one option at a time to see which, if any of the options work
Upvotes: 0