1
我有兩個問題與我的批處理文件,我認爲它們是由於EnableDelayedExpansion
。使用EnableDelayedExpansion時變量的問題
我基於this post from SO我的腳本。
我需要EnableDelayedExpansion
作爲我腳本的另一部分,所以我需要保留它。
這是我的腳本:
@echo off
set myPath=Subfolder1
set folderList=input.txt
set originalPath=%~dp0
cd %myPath%
setlocal EnableDelayedExpansion
:process
for /F "tokens=*" %%S in (%~dp0\%folderList%) do (
echo Folder %%S
REM echo Folder %%S prints: Folder folderName
set testPath=C:\BatchTests\%%S\
echo test path: %testPath%
REM echo test path: %testPath% prints: test path:
)
echo %originalPath%
REM echo %originalPath% prints: C:\BatchTests\
cd %originalPath%
pause
testPath
似乎總是空的,而行cd %originalPath%
。
我在做什麼錯?什麼是正確的方式使用/設置testPath
?
The second issue I am having is different, so I opened a separate question here.
用'!testPath!'試試吧! – jeb
當使用'pushd%myPath%'臨時修改它並且'popd'恢復原來的目錄時,您不需要將工作目錄存儲在變量中... – aschipfl
@ jeb - 那有效!那是另一種使用變量的方法嗎? – Dzyann