所以,我制作了一个批处理脚本,它执行多个可移植程序(例如,prog1.exe,prog2.exe等).问题是每当我将USB驱动器连接到另一台计算机时,驱动器号都会改变,在运行我的.bat文件时会出现错误.请帮我找一个解决方案.谢谢.
Joh*_*van 16
%~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