中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-06-19 18:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [已结]删除D盘下除GAME和MENU外的其余所有文件夹 查看 803 回复 5
楼 主 [已结]删除D盘下除GAME和MENU外的其余所有文件夹 发表于 2008-12-17 04:55 ·  中国 山西 太原 联通
初级用户
积分 42
发帖 37
注册 2008-12-05 23:59
17年会员
UID 133025
性别 男
状态 离线
比如我想删除D盘下除GAME和MENU外的其余所有文件夹
@echo off
attrib -s -r d:\*.*
for /d %%a in (game,menu) do attrib +s +r d:\"%%a"
for /d %%b in (d:\*.*) do rmdir "%%b" /q
pause&exit


求一步到位一句FOR解决掉!

[ Last edited by HAT on 2008-12-17 at 14:19 ]
2 发表于 2008-12-17 05:12 ·  中国 山西 太原 联通
初级用户
积分 42
发帖 37
注册 2008-12-05 23:59
17年会员
UID 133025
性别 男
状态 离线
for /f "usebackq delims=" %%a in ('dir /a:d /b d:^|findstr /i /v "game menu"') do rmdir /q "d:\%%a"

这样显示语法不正确

而下面这样又可以
dir /a:d /b d:|findstr /i /v "game menu" >rmdir.txt
for /f "usebackq delims=" %%a in (rmdir.txt) do rmdir /q "d:\%%a"

帮忙修改一下啊

[ Last edited by 15935643331 on 2008-12-17 at 06:17 ]
3 发表于 2008-12-17 06:24 ·  中国 山西 太原 联通
初级用户
积分 42
发帖 37
注册 2008-12-05 23:59
17年会员
UID 133025
性别 男
状态 离线
' '
① 在for/f中表示将它们包含的内容当作命令行执行并分析其输出。
② 在for/f "usebackq"中表示将它们包含的字符串当作字符串分析。
for /f "delims=" %%a in ('dir /a:d /b d:^|findstr /i /v "game menu"') do rmdir /q "d:\%%a"
4 发表于 2008-12-17 10:34 ·  中国 江西 赣州 电信
银牌会员
★★★★
积分 2,025
发帖 1,122
注册 2007-09-05 20:15
18年会员
UID 96653
性别 男
状态 离线
@echo off
for /d %%a in (D:\*) do (
if /i "%%~na" neq "GAME" if /i "%%~na" neq "MENU" rd /s /q "%%a"
)
5 发表于 2008-12-17 14:05 ·  中国 山西 太原 联通
初级用户
积分 42
发帖 37
注册 2008-12-05 23:59
17年会员
UID 133025
性别 男
状态 离线
谢谢
if /i "%%~na" neq "GAME"
写出来就可以学习了

if /i 要进行的字符串比较不分大小写
neq 不等于
"%%~na" 扩展到文件夹名?

问一下,怎么查看扩展变量的用法?一点都不懂!
6 Re 5楼 发表于 2008-12-17 14:19 ·  美国 惠普HP
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
多看基础教程和帮助
for /?
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
论坛跳转: