因此,我制作了一个批处理脚本,它执行多个可移植程序(例如 prog1.exe、prog2.exe 等)。问题是每当我将 USB 驱动器连接到另一台计算机时,驱动器号就会发生变化,从而在运行 .bat 文件时出现错误。请帮我找到解决方案。谢谢。
%~d0
为您提供当前驱动器号(包括冒号)。如果批处理文件包含在 USB 驱动器上,您就可以使用它。
所以,例如,而不是
E:\PortablePrograms\ProgramName.exe
你会写
%~d0\PortablePrograms\ProgramName.exe
...或者你可以做这样的事情
::change directory to the script's directory's drive
pushd %~d0
::navigate from the drive to the relevant path(s)
cd PortablePrograms
::execute any programs
ProgramName.exe
SecondProgramName.exe
::just because I like to pair my pushes with pops; not required
popd
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)