Created
September 16, 2011 12:05
-
-
Save jinwei233/1221959 to your computer and use it in GitHub Desktop.
批处理笔记
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shell 获取当前目录 | |
设置环境变量 | |
打印环境变量 | |
%0 是指批处理文件本身 | |
%~dp0 是对%0的扩展,d是drive,也就是盘符,p是路径,所以%~dp0是指批处理所在的路径(包括盘符) | |
pushd是设定工作目录 | |
所以 PUSHD %~dp0 就是设定批处理所在的目录为工作目录 | |
"%~dp00PE_0606_for_ud"也就是批处理所在目录下0PE_0606_for_ud目录 | |
PUSHD临时指定当前路径. | |
一般和POPD配套使用.(回到上一个PUSHD前的路径) | |
也可以用于SETLOCAL语句中防止运行目录被改变. | |
例子 | |
CD /D C:\WINDOWS | |
echo.当前目录是%cd% | |
PUSHD %~dp0 | |
echo.当前目录是%CD% | |
popd | |
echo.当前目录是%cd% | |
call :test | |
echo.调用一个批处理标签后当前目录是%cd% | |
goto :eof | |
:test | |
setlocal | |
pushd e:\ | |
echo.当前目录是%cd% | |
goto :eof | |
通过以上的例子就可以发现PUSHD和CD的区别. | |
%comspec% | |
打开一个命令行窗口。%comspec% 是一个指向当前命令行外壳的环境变量。通过使用 %comspec%,您不必担心命令行外壳是 cmd.exe 还是 command.exe;%comspec% 会自动选择正确的一个。 | |
/k | |
在调用 Dir 命令后,确保窗口始终保持打开。这就是 /k 参数的用处。如果我们想要确保命令窗口会在 Dir 命令调用完成后被自动关闭,应该将 /k (keep) 修改为 /c (close)。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment