批处理 - 带空格的路径

Batch - Path with spaces

大家好,看我问题的人, 我一直在玩文件,我尝试了一些东西 "start /D %appdata%\Microsoft\Windows\Start Menu\Programs\Startup\<File>.bat"

我这样做是为了制作一个循环,当它完成时再次运行 bat 文件。 当我对此进行测试时出现错误

"C:\Windows\System32>start /D %appdata%\Microsoft\Windows\Start Menu\Programs\Startup\.bat The system cannot find the file Menu\Programs\Startup\.bat."

<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
start /D AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\<File>.bat

如果您知道解决此问题的方法或改进我的球棒的方法,请告诉我!

注: 我以管理员身份运行它并且 .bat 文件位于启动文件夹中。

由于路径中有一个 space,您需要将其括起来,并且 /D 需要起始目录的文件夹路径。在本例中,它将 %AppData%\Microsoft\Windows\Start 解释为启动文件夹,将 Menu\Programs\Startup\File.bat 解释为要执行的文件。我很确定你不是那个意思。您不需要指定 /D 开关,除非您的批处理文件通过 /D 之后指定的文件夹的相对路径引用外部依赖项。

如果您的默认 Windows 启动文件夹中有一个批处理文件,这将执行它:

start "" "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\File.bat"

在我看来,问题不在于文件名,而在于批处理文件如何引用自身或循环。

因此:

要么对最后一行使用 %0 表示法,例如Start "" "%~f0""%~f0"

<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
Start "" "%~f0"

或者在顶部放置一个标签 :Label 然后作为底线,GoTo :Label.

:Label
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
<Here is a command>
GoTo :Label

附带说明一下,您可能希望在 login/startup 查看 运行 脚本的计划任务,并在此后定期继续执行此操作。