Board logo

标题: [已结]使用for清理空目录的问题。 [打印本页]

作者: zuimeng     时间: 2008-10-31 12:03    标题: [已结]使用for清理空目录的问题。

由于是测试命令,都是在命令提示符下直接运行的。

>>c:\ct.txt
是为看命令执行情况

先清理临时文件,运行成功。
for /d %a in ("%systemdrive%\Documents and Settings\*") do (del /f /s /q "%a\Local Settings\Temp\*.*">>c:\ct.txt& del /f /s /q "%a\Local Settings\Temporary Internet Files\*.*">>c:\ct.txt)
再清理空目录
for /d %a in ("%systemdrive%\Documents and Settings\*") do (for /d %b in ("%a\Local Settings\Temp\*") do rd /s /q %b>>c:\ct.txt)

for /d %a in ("%systemdrive%\Documents and Settings\*") do (for /d %b in ("%a\Local Settings\Temporary Internet Files\*") do rd /s /q %b>>c:\ct.txt)
发现一执行出现二个问题

第二个for 后/d参数的字符d没有了。
%b的后面总会多出一个空格和一个1的二个字符,导致%b的值也多了这二个字符。(这个现像在清理文件时也有,但不影响执行)

效果如下:
C:\Documents and Settings\xz03>(for / %b in ("C:\Documents and Settings\All User
s\Local Settings\Temporary Internet Files\*") do rd /s /q %b 1>>c:\ct.txt )

C:\Documents and Settings\xz03>(for / %b in ("C:\Documents and Settings\XING03\L
ocal Settings\Temporary Internet Files\*") do rd /s /q %b 1>>c:\ct.txt )

C:\Documents and Settings\xz03>(for / %b in ("C:\Documents and Settings\xz03\Loc
al Settings\Temporary Internet Files\*") do rd /s /q %b 1>>c:\ct.txt )

C:\Documents and Settings\xz03>rd /s /q C:\Documents and Settings\xz03\Local Set
tings\Temporary Internet Files\AntiPhishing 1>>c:\ct.txt
[ Last edited by HAT on 2008-11-1 at 11:34 ]
作者: HAT     时间: 2008-10-31 12:23


  Quote:
%b的后面总会多出一个空格和一个1的二个字符,导致%b的值也多了这二个字符。(这个现像在清理文件时也有,但不影响执行)

本版搜索重定向
多看看教程就明白了
作者: zuimeng     时间: 2008-10-31 14:09
谢谢,明白。

解决 了。