在尝试将第三个 for 循环和它的支持代码集成到现有代码中时,我已经达到了我理解的极限。我完全不知道如何在这个复杂的“EnableDelayedExpansion”环境中引用各种变量。
此外,应该在每个 For 循环中打开/关闭“EnableDelayedExpansion”/endlocal,还是在程序开始和结束时打开/关闭一次。
:: ------------------ Beg For #1
For /L %%a in (%XBEG%,1,%XEND%) do (
cls
echo : %%a
set L=1
:: ------------------ Beg For #2
For /F "delims=" %%b in (%XDRV%%XPATH%%%a\1dir%%a.txt) do (
set XTITLE=%%b
echo Line !L!: !XTITLE!
If not {!XTITLE!}=={!XTITLE:%XDRV%%XPATH%%%a\!} set XTITLE=!XTITLE:~18,-4!
::
:: ------------------ Beg For #3 --- New code
:: Write title to the xtemp file. Place the redirection
:: symbol, i.e., greater than sign, IMMEDIATELY after vari
:: to avoid a trailing space, i.e., ( %vari%> )
echo !XTITLE!> %XDRV%%XPATH%xtemp.txt
:: Get the file size in bytes, each byte = one character
For %%c in (%XDRV%%XPATH%xtemp.txt) do set /a XLEN=%%~zc
:: Subtract 2 bytes, 1 for CR, 1 for LF, from Length
set /a XLEN -=2
cls
echo : ===[ Debug ]======================================
echo - !XTITLE! - has !XLEN! characters.
set /a XPAD=50-!XLEN!
echo - Xpad is !XPAD!
:: Build the Index entry
set XENTRY=%XPADs%%XTITLE%%XPAD%%%a
echo - %XENTRY%
pause
:: remove the xtemp file
del %XDRV%%XPATH%xtemp.txt
set /a L=!L!+1
pause
:: ------------------ end of New code
):: End For #2
)
:: End For #1
:: Clean Up For3
set XTITLE=
set L=
Goto DOS
“EnableDelayedExpansion”/endlocal 当前放置在程序的开头和结尾。
我希望这种情况对社区有足够的兴趣,因为迫切需要您的帮助并且非常感谢。