bat 获取当前目录的父目录 @echo off echo batchfile=%0 echo full=%~f0 setlocal for %%d in (%~dp0.) do set Directory=%%~fd echo Directory=%Directory% for %%d in (%~dp0..) do set ParentDirectory=%%~fd echo ParentDirectory=%ParentDirectory% endlocal pause
批处理bat命令--获取当前盘符和当前目录和上级目录 批处理命令获取当前盘符和当前目录%~d0 是当前盘符%cd% 是当前目录可以用echo %cd%进行打印测试 以下例子是命令行编译Visual Studio编写的程序:@echo offset b=%cd% //将当前目录保存到参数b中,等号前后不要有空格C:cd program filescd microsoft visual studio cd common cd msdev98cd binmsdev "%b%\test.dsp"