【发布时间】:2015-04-09 17:27:03
【问题描述】:
不确定这个批处理文件代码的确切问题是什么。我在 CMD 窗口中以管理员身份运行它。它一直运行到IF NOT 语句的位置。我已经包含了输出(在代码下方),以使查看它的人尽可能容易。
此代码的目的是从pInstallDir 环境变量中的路径中删除最后一个子目录。
例如:pInstallDir="C:\program Files (x86)\uploads\field"
此代码应从pInstallDir 末尾删除一个字符,直到找到反斜杠\。这将使pInstallDir 的内容等于"C:\program Files (x86)\uploads"
我确定我遗漏了一些明显的东西。任何帮助将不胜感激。
echo Cleaning up Directories
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set pInstallDir="C:\Program Files(x86)\uploads\field\"
set pInstallDir=%pInstallDir:"=%
IF "%pInstallDir:~-1%"=="\" SET pInstallDir=%pInstallDir:~0,-1%
set nf="1"
:r_str
IF NOT "%pInstallDir:~-1%"=="\" (SET pInstallDir=%pInstallDir:~0,-1%) else (set nf="0")
echo %pInstallDir%
if "%nf%"=="1" (goto r_str) else (goto done)
pause
:done
IF %pInstallDir:~-1%"=="\" SET pInstallDir=%pInstallDir:~0,-1%
echo %pInstallDir%
输出
(回声关闭)
Cleaning up Directories
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set pInstallDir=C:\Program Files(x86)\uploads\field\
IF "\" == "\" SET pInstallDir=C:\Program Files(x86)\uploads\field
set nf="1"
\uploads\fiel) was unexpected at this time.
IF NOT "d"=="\" (SET pInstallDir=C:\Program Files(x86)\uploads\fiel) else (set nf="0")
代码在上面一行之后自行退出。
【问题讨论】:
标签: batch-file cmd environment-variables