遞迴訪問目錄樹中的目錄
for /r 命令可用於遞迴訪問目錄樹中的所有目錄並執行命令。
@echo off
rem start at the top of the tree to visit and loop though each directory
for /r %%a in (.) do (
rem enter the directory
pushd %%a
echo In directory:
cd
rem leave the directory
popd
)
筆記:
- for / r - 迴圈檔案(Recurse 子資料夾)。
- pushd - 更改當前目錄/資料夾並儲存以前的資料夾/路徑以供 POPD 命令使用。
- popd - 將目錄更改回 PUSHD 命令最近儲存的路徑/資料夾。