旗帜延迟扩张'在批处理文件中启用。它始于:
@echo off
setlocal EnableDelayedExpansion
批处理文件打算生成所有' .c'当前文件夹及其所有子文件夹中的文件。这是:
:: -------------------
:: Generate file tree
:: -------------------
@echo off
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
:: 1. Delete old file trees
:: -------------------------
for /r %%x in (*FileTree.txt) do (
REM echo."File %%x deleted"
del "%%x"
)
:: 2. Generate new file tree
:: -------------------------
break > localFileTree.txt
set mypath=
set localPath=
call :treeProcess
goto :eof
:treeProcess
setlocal
for %%f in (*.c) do (
set localPath=%mypath%%%f
echo.!localPath! >> %~dp0\localFileTree.txt
)
for /D %%d in (*) do (
set mypath=%mypath%%%d\
echo.!mypath!
cd %%d
call :treeProcess
cd ..
)
endlocal
exit /b
可以通过多种方式引用变量:
mypath=...
%%f
或%%d
%mypath%
!mypath!
我有点困惑。我知道它与“延迟扩张”有关。打开的标志。但是这些变量引用如何实际上彼此不同?