中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 17:20
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » [Help] How to delete unnecessary folders under drive D every time the computer boots up
Printable Version  2,481 / 8
Floor1 enty2008 Posted 2006-05-06 17:42
新手上路 Posts 1 Credits 6
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 ]
Floor2 Wengier Posted 2006-05-06 23:36
系统支持 Posts 10,521 Credits 27,736
This post should be posted in the "DOS Batch & Script Technology (Batch Processing Room)" section, so now it is transferred here.
Floor3 3742668 Posted 2006-05-07 11:50
荣誉版主 Posts 718 Credits 2,013
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.



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.
Floor4 tigerpower Posted 2006-05-07 17:15
中级用户 Posts 99 Credits 377
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.
Floor5 3742668 Posted 2006-05-07 17:31
荣誉版主 Posts 718 Credits 2,013
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.
Floor6 dawnerlee Posted 2006-05-09 20:39
新手上路 Posts 4 Credits 8
Learning
It's so profound.
Floor7 tigerpower Posted 2006-05-09 21:12
中级用户 Posts 99 Credits 377
The main thing the poster should pay attention to is that the original three folder names must have no spaces.
Floor8 kingljp Posted 2006-05-10 01:02
初级用户 Posts 29 Credits 80
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.
Floor9 3742668 Posted 2006-05-10 13:44
荣誉版主 Posts 718 Credits 2,013
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023