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-07-08 19:57
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to "simplify" the following batch processing with a FOR loop? (How to pass >> to a variable?) View 1,971 Replies 3
Original Poster Posted 2005-04-16 00:00 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
How to use a FOR loop to "simplify" the following batch processing to write the drive letters in findd.txt to the drive.txt file (for WBAT to call)?

find "C:\" findd.txt >nul
if not errorlevel 1 echo C:>>drive.txt
find "D:\" findd.txt >nul
if not errorlevel 1 echo D:>>drive.txt
find "E:\" findd.txt >nul
....

Floor 2 Posted 2005-04-16 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 GOTOmsdos: Although using a FOR loop is also achievable, I do not recommend using it because it is not flexible in controlling internal processes; I suggest you use a command-line loop. I once wrote several similar programs for兄 walu, and you can refer to and modify them using the following links:
http://bbs.cn-dos.net/dispbbs.asp?boardid=12&id=9637
http://bbs.cn-dos.net/dispbbs.asp?boardid=9&id=11963
http://bbs.cn-dos.net/dispbbs.asp?boardid=12&id=14552
http://bbs.cn-dos.net/dispbbs.asp?BoardID=9&ID=14512
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2005-04-16 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
In pure DOS, it can't be nested like this. Looking at the building's program, it should be under pure DOS, so SHIFT should be used.
http://www.msfans.net/bbs/
Floor 4 Posted 2005-04-16 00:00 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
Thanks for the reminder, just use SHIFT with a parameter. It's really difficult with FOR!drive.bat:
@echo off
:loop
if "%1"=="" goto end
find "%1" findd.txt>nul
if not errorlevel 1 echo %1>>drive.txt
shift
goto loop
:end
Input: drive c: d: e: ....
Forum Jump: