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-13 10:38
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Please enter the command to traverse all folders in the hard disk in .bat format. ```batch @echo off for /r "C:\" %%i in (.) do ( echo %%i ) ``` Above is a simple .bat script example. It uses the `for /r` command to recursively traverse all folders starting from the root directory of the C drive (you can change "C:\" to other drive letters as needed).在.bat中请教如何遍历硬盘中的所有文件夹 请输入以.bat格式遍历硬盘中所有文件夹的命令 ```batch @echo off for /r "C:\" %%i in (.) do ( echo %%i ) ``` 上面是一个简单的.bat脚本示例,它使用`for /r`命令从C盘根目录开始递归遍历所有文件夹(你可以根据需要将"C:\"改为其他盘符)Please enter the command to traverse all folders in the hard disk in .bat format. ```batch @echo off for /r "C:\" %%i in (.) do ( echo %%i ) ``` Above is a simple .bat script example. It uses the `for /r` command to recursively traverse all folders starting from the root directory of the C drive (you can change "C:\" to other drive letters as needed). ### 步骤解释: 1. `@echo off`:关闭命令回显,使脚本执行时不显示命令本身。 2. `for /r "C:\" %%i in (.) do (`:`for /r`表示递归遍历,后面的路径是起始路径,这里是C盘根目录,`%%i`是循环变量,`in (.)`表示遍历的对象是文件夹(`.`表示文件夹)。 3. `echo %%i`:输出当前遍历到的文件夹路径。 如果要遍历其他硬盘分区,比如D盘,只需要将`"C:\"`改为`"D:\"`即可。To ask how to traverse all folders in the hard disk in .bat, please enter the command in .bat format for traversing all folders in the hard disk. ```batch @echo off for /r "C:\" %%i in (.) do ( echo %%i ) ``` The above is a simple example of a .bat script. It uses the `for /r` command to recursively traverse all folders starting from the root directory of the C drive (you can change "C:\" to other drive letters as needed). ### Step explanation: 1. `@echo off`: Turns off command echoing, so that the command itself is not displayed when the script is executed. 2. `for /r "C:\" %%i in (.) do (`: `for /r` means recursive traversal, the following path is the starting path, here it is the root directory of the C drive, `%%i` is the loop variable, `in (.)` means the object to be traversed is a folder (`.` means a folder). 3. `echo %%i`: Outputs the path of the currently traversed folder. If you want to traverse other hard disk partitions, such as the D drive, you only need to change `"C:\"` to `"D:\"`. View 1,956 Replies 6
Original Poster Posted 2004-01-21 00:00 ·  中国 重庆 南岸区 联通
初级用户
★★
Credits 311
Posts 62
Joined 2003-08-16 00:00
22-year member
UID 8721
Gender Male
Status Offline
Got infected with Happy Time, used the special kill tool to kill it, but couldn't delete desktop.ini and folder.htt that are all over the hard drive. Want to write a program, but don't know how to traverse folders. Asking for help! 3x!!!!!!!!!!!!!!!!!1
一切都会好起来的
Floor 2 Posted 2004-01-21 00:00 ·  中国 辽宁 沈阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
The following is a quote from winddeity on 2004-1-21 3:45:00:
I got the Happy Time virus. I used the special killing tool to kill it, but I couldn't delete desktop.ini and folder.htt that are all over the hard disk.
I want to write a program, but I don't know how to traverse folders. Please help!
3x!!!!!!!!!!!!!!!!!1


You can use the DOS version of PKZIP to complete this task. Here is a batch file I wrote, you can give it a try.

@ECHO OFF
CD\
IF EXIST C:\TMP^TMP.ZIP DEL C:\TMP^TMP.ZIP
PKZIP.EXE -a -exx -p -r -o -= -a+ -n+ -! -m C:\TMP^TMP.ZIP desktop.ini > NUL
PKZIP.EXE -a -exx -p -r -o -= -a+ -n+ -! -m C:\TMP^TMP.ZIP folder.htt > NUL
DEL C:\TMP^TMP.ZIP

Note: This method will delete all DESKTOP.INI and FOLDER.HTT files on the disk. If you want to keep these two files in the system directory (such as the WINDOWS directory), please back up these two files in the system directory first, and then restore these two files after performing this operation. It is specially noted that you must clear the virus completely before performing the backup, remember! Remember! Good luck to you! Also, I wish you a happy Spring Festival!

The download link for PKZIP is as follows:

http://model.chinajewelry.net/dos/dosbbs/uploadImages/200311251526137234.rar
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 3 Posted 2004-01-21 00:00 ·  中国 重庆 联通
初级用户
★★
Credits 311
Posts 62
Joined 2003-08-16 00:00
22-year member
UID 8721
Gender Male
Status Offline
Completed the task successfully, thank you very much, Brother kinglion

Wish you a happy New Year too!
一切都会好起来的
Floor 4 Posted 2004-01-21 00:00 ·  中国 重庆 南岸区 联通
初级用户
★★
Credits 311
Posts 62
Joined 2003-08-16 00:00
22-year member
UID 8721
Gender Male
Status Offline
The problem is solved, but I still want to know if there is a way to traverse folders under bat. Please teach the experts!
3x!!
Also wish you all a happy Spring Festival!
一切都会好起来的
Floor 5 Posted 2004-02-04 00:00 ·  中国 江苏 南京 联通
初级用户
Credits 140
Posts 18
Joined 2004-02-03 00:00
22-year member
UID 16630
Gender Male
Status Offline
dir /s
Is it okay?
If you don't want echo, use a pipe to output the echo to NUL.
Floor 6 Posted 2004-02-06 00:00 ·  中国 山西 太原 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re winddeity:

The following is a sample code. I'll write the complete code when I have a machine;

  http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=12&ID=9350
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2004-03-13 00:00 ·  中国 山东 烟台 芝罘区 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re winddeity:

This is the complete code, which has been tested and passed!
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=6&ID=9588
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: