<Bat>批处理删除指定文件,for循环只宜有一条语句

来源:互联网 发布:linux查核指令 编辑:程序博客网 时间:2024/05/19 22:24

想清理VS2010工程目录下的中间文件Debug/Release文件夹。

@echo offset curpath=%~dp0echo 正在清理垃圾文件,请稍候...... for /f "delims=" %%i in ('dir /b .') do call :delete_dir %%ifor /r . %%a in (.) do @if exist "%%a\ipch" rd /s /q "%%a\ipch" for /r . %%a in (.) do @if exist "%%a\*.sdf" del /s /f "%%a\*.sdf"for /r . %%a in (.) do @if exist "%%a\*.ilk" del /s /f "%%a\*.ilk"for /r . %%a in (.) do @if exist "%%a\*.pdb" del /s /f "%%a\*.pdb"echo 清理完毕!!! pause:delete_dirset "prjDir=%1"set "dbgDir=%curpath%%prjDir%\%prjDir%\Debug"set "rlsDir=%curpath%%prjDir%\%prjDir%\Release"REM echo __%prjDir%__REM echo __%dbgDir%__REM echo __%rlsDir%__if exist "%dbgDir%"  rd /s /q "%dbgDir%" if exist "%rlsDir%"  rd /s /q "%rlsDir%" goto :EOF

其中for循环,如果换成以下方式:

for /f "delims=" %%i in ('dir /b .') do (set "prjDir=%%i"set "dbgDir=%curpath%%prjDir%\%prjDir%\Debug"set "rlsDir=%curpath%%prjDir%\%prjDir%\Release"REM echo __%prjDir%__REM echo __%dbgDir%__REM echo __%rlsDir%__if exist "%dbgDir%"  rd /s /q "%dbgDir%" if exist "%rlsDir%"  rd /s /q "%rlsDir%" )


要么%%i是空的,要么就一直会最后的值,反正不会变为。for循环只宜带一条语句。