%%f in a batch file with Windows 7 Professional 64 bit
I have a line like the following in a several batch files:
FOR %%f IN (%*) DO something.exe %%fI've used them for a long time with no problem. I recently had to replace my hard drive and had Windows 7 reinstalled just as it was before as far as I know. Now when I run any of the batch files with this kind of line in it, they aren't pre-processing the "%*". So for something like "XXX.bat *.txt" I get:
Unable to open input file "*.txt"
I'm running Windows 7 as a virtual machine in Parallels, upgraded from version 8 to 10, if that makes a difference. They also upgraded my Mac OS from Mountain Lion to Yosemite.
Even more strange, this little batch file works fine:
@ECHO off
FOR %%f IN (%*) DO start gvim %%fBut this one gives the message it can't find t? (where t? should parse out to t1, t2, and t3):
@ECHO off
FOR %%f IN (%*) DO af2.exe %%fAnd I tried adding the "start" to it, same results.
Maybe a simpler way of saying it is:
This works:
af2 2014A 2014B 2014C
But this:
af2 2014?
gives an error about trying to access a file called "2014?"
And af2 calls, for each file, a program I wrote and have used for 20+ years that just gives a few statistics on a file.
42 Answers
Command Extensions are disabled for some reason. The command extensions involve serious changes to Command Line arguments (Parameters) as per CALL /?.
However, next excerpt from CMD /? shows some solution hints:
Command Extensions are enabled by default. You may also disable extensions for a particular invocation by using the
/E:OFFswitch. You can enable or disable extensions for all invocations ofCMD.EXEon a machine and/or user logon session by setting either or both of the followingREG_DWORDvalues in the registry usingREGEDIT.EXE:HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensionsand/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensionsto either
0x1or0x0. The user specific setting takes precedence over the machine setting. The command line switches take precedence over the registry settings.In a batch file, the
SETLOCAL ENABLEEXTENSIONSorDISABLEEXTENSIONSarguments takes precedence over the/E:ONor/E:OFFswitch. SeeSETLOCAL /?for details.
Example
==>type D:\bat\cliParser.bat
@echo OFF >NUL
echo all %%* = %*
set /A "ii=0"
:loopfor echo param %%%ii% = %0 SHIFT set /A "ii+=1" if not [%0]==[] goto :loopfor
goto :eof
==>D:\bat\cliParser.bat aaa bbb all %* = aaa bbb
param %0 = D:\bat\cliParser.bat
param %1 = aaa
param %2 = bbb
==>cmd /E:OFF /C D:\bat\cliParser.bat aaa bbb all %* = *
The syntax of the command is incorrect.
param %3 = D:\bat\cliParser.bat
The syntax of the command is incorrect.
param %3 = aaa
The syntax of the command is incorrect.
param %3 = bbb
The syntax of the command is incorrect.
The system cannot find the batch label specified - eof
==> 1 I figured out the problem. I have a folder on my desktop with a bunch of .exe files in them from programs I've written. It also has a folder with some .bat files in it. In many cases, the .bat file calls one of the .exe files that has the same root name (af2.bat calls af2.exe). That works fine IF the folder with the .bat files in it precedes the other folder in the PATH variable, which it did on my previous install (and does now on this one).
Just gotta love those subtle little problems.
Thanks for all the input. :)