中国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-08-13 09:35
47,811 topics / 349,897 posts / today 0 new / 48,256 members
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:\"`.
Printable Version  1,954 / 6
Floor1 winddeity Posted 2004-01-21 00:00
初级用户 Posts 62 Credits 311
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
Floor2 Kinglion Posted 2004-01-21 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
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
Floor3 winddeity Posted 2004-01-21 00:00
初级用户 Posts 62 Credits 311
Completed the task successfully, thank you very much, Brother kinglion

Wish you a happy New Year too!
Floor4 winddeity Posted 2004-01-21 00:00
初级用户 Posts 62 Credits 311
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!
Floor5 songjian Posted 2004-02-04 00:00
初级用户 Posts 18 Credits 140
dir /s
Is it okay?
If you don't want echo, use a pipe to output the echo to NUL.
Floor6 willsort Posted 2004-02-06 00:00
元老会员 Posts 1,512 Credits 4,432
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
Floor7 willsort Posted 2004-03-13 00:00
元老会员 Posts 1,512 Credits 4,432
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
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023