遍历目录1(只遍历一级目录)
@echo off
set addisk="E:"
set cpddisk=c:
setlocal EnableDelayedExpansion
for /d %%i in (%systemdrive%\*) do (
set x=%%i
set x=!x:~2!
echo !x!
rem mklink /J "%Addisk%!x!" "%CPddisk%!x!" 1>nul 2>nul
)
pause
遍历目录2(遍历所有目录)
@echo off
setlocal EnableDelayedExpansion
for /r %%a in (.) do (
set dirx=%%a
set dirx=!dirx:~,-2!
echo !dirx!
)
pause
dir遍历文件(可列举隐藏文件)
@echo off
set file=*.*
rem set Dir=C:\Documents and Settings\Administrator\Application Data\Autodesk\
rem cd /d "%Dir%"
for /f "delims=" %%i in ('dir /b /a-d /s %file%') do (echo "%%i")
echo 操作已完成,任意键退出
pause