Works in Command Prompt but not in BAT-file or CMD-file [duplicate]

喜欢而已 提交于 2019-12-13 11:23:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!