China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 15:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to delete unnecessary folders under drive D every time the computer boots up View 2,305 Replies 8
Original Poster Posted 2006-05-06 17:42 ·  中国 福建 厦门 电信
新手上路
Credits 6
Posts 1
Joined 2006-05-06 17:40
20-year member
UID 55049
Status Offline
Originally, there were three folders in drive D: Lgames, Ngames, and Game Menu. How to use a batch file to delete redundant folders under drive D and their contents each time the computer starts?

[ Last edited by willsort on 2006-5-11 at 17:21 ]
Floor 2 Posted 2006-05-06 23:36 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
This post should be posted in the "DOS Batch & Script Technology (Batch Processing Room)" section, so now it is transferred here.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 3 Posted 2006-05-07 11:50 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
First, extract the directory names using dir /ad /b, then use findstr /v to filter out the directories that are not to be deleted, and finally use for to traverse the list.


@echo off
for /f "tokens=*" %%i in {'"dir d: /ad /b | findstr /i /v "Lgames Ngames 游戏菜单""') do rd /s /q "%%i"


Notes:
1. If there are Chinese characters in the findstr search string, the /i parameter needs to be added.
2. Considering that there may be spaces in the folder name, for /f should specify tokens=*, and when the rd command calls %%i, quotes should be added.
3. When using the output of a certain command as the loop condition of for, it is best to add another pair of double quotes inside the single quotes in the parentheses, which can avoid explicit character escaping and possible problems.
Floor 4 Posted 2006-05-07 17:15 ·  中国 上海 长宁区 电信
中级用户
★★
大师兄
Credits 377
Posts 99
Joined 2005-08-26 07:37
20-year member
UID 41945
Status Offline
There is a special case, that is, there happens to be a folder like "Second Game Menu" under the d:\. It would be even more perfect if such a situation can be handled.
Floor 5 Posted 2006-05-07 17:31 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
RE tigerpower:
You can add the /x parameter when calling findstr. If the folder name is specified incorrectly, it may mistakenly delete folders that should not be deleted. If used in a script that interacts with directory names, be cautious.
Floor 6 Posted 2006-05-09 20:39 ·  中国 北京 海淀区 北龙中网(北京)科技有限公司(BGP)
新手上路
Credits 8
Posts 4
Joined 2006-05-01 00:27
20-year member
UID 54750
Status Offline
Learning
It's so profound.
Floor 7 Posted 2006-05-09 21:12 ·  中国 上海 长宁区 电信
中级用户
★★
大师兄
Credits 377
Posts 99
Joined 2005-08-26 07:37
20-year member
UID 41945
Status Offline
The main thing the poster should pay attention to is that the original three folder names must have no spaces.
Floor 8 Posted 2006-05-10 01:02 ·  中国 广西 河池 金城江区 电信
初级用户
Credits 80
Posts 29
Joined 2006-05-03 03:20
20-year member
UID 54852
Status Offline
Originally posted by 3742668 at 2006-5-7 11:50:
First of all, use dir /ad /b to extract the directory names, then use findstr /v to filter out the directories that should not be deleted, and finally use for to traverse the list.

@echo off
for /f "tokens=*" %%i ...

Here I want to ask, how do you distinguish which files should be deleted and which should not be deleted.
Floor 9 Posted 2006-05-10 13:44 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Re tigerpower:
You can take a good look at findstr /?, it's not impossible to achieve.
I think this post isn't mainly about how findstr filters characters. The楼主has already specified the names of the three folders. If you're interested in discussing the topic of character filtering, please start a new post.
Re kingljp:
The command used to distinguish which files should be deleted and which shouldn't is:dir d: /ad /b | findstr /i /v "Lgames Ngames 游戏菜单". Since the楼主has specified that these three folders should not be deleted, you just need to delete these three folder names from the list, and the rest are the ones that should be deleted.
Forum Jump: