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

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

@echo off

set curpath=%~dp0
echo 正在清理垃圾文件,请稍候...... 

for /f "delims=" %%i in ('dir /b .') do call :delete_dir %%i

for /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_dir
	set "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循环只宜带一条语句。



你可能感兴趣的:(Windows)