问题
Due to problem with WINDOWS DEFENDER I need do the following:
for /r "%appdata%\..\Local\MyProg\2.0" %D IN ("*MyProgram.exe") DO "%~fD
It works perfect in COMMAND PROMPT but not in batch-file or cmd-file - why?
How do I make in a excutable file as a Batch-file or ".cmd"?
回答1:
When running for loops in a batch file, you need to use an additional % in predefined variables. So it should be:
for /r "%appdata%\..\Local\MyProg\2.0" %%D IN ("*MyProgram.exe") DO "%%~fD
I suggest you read up using the well documented help by running for /? from cmdline. You will benefit from it, guaranteed!
回答2:
A recursive For loop already returns the full path, additionally there's already a system variable for the path %AppData%\..\Local.
For /R "%LocalAppData%\MyProg\2.0" %%A In ("*MyProgram.exe") Do "%%A"
Depending upon your needs, it may be worth checking out the Start command usage too, Start /?. You may find that Do Start "" "%%A" is what you needed.
来源:https://stackoverflow.com/questions/50530157/works-in-command-prompt-but-not-in-bat-file-or-cmd-file