中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-10 04:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [已结]使用for清理空目录的问题。 查看 644 回复 2
楼 主 [已结]使用for清理空目录的问题。 发表于 2008-10-31 12:03 ·  中国 浙江 温州 电信
初级用户
★★
积分 170
发帖 83
注册 2007-11-30 16:44
18年会员
UID 104263
性别 男
状态 离线
由于是测试命令,都是在命令提示符下直接运行的。

>>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 ]
2 发表于 2008-10-31 12:23 ·  美国 惠普HP
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
%b的后面总会多出一个空格和一个1的二个字符,导致%b的值也多了这二个字符。(这个现像在清理文件时也有,但不影响执行)

本版搜索重定向
多看看教程就明白了
3 发表于 2008-10-31 14:09 ·  中国 浙江 温州 电信
初级用户
★★
积分 170
发帖 83
注册 2007-11-30 16:44
18年会员
UID 104263
性别 男
状态 离线
谢谢,明白。

解决 了。
论坛跳转: