中国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 14:38
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » How to "simplify" the following batch processing with a FOR loop? (How to pass >> to a variable?)
Printable Version  2,106 / 3
Floor1 GOTOmsdos Posted 2005-04-16 00:00
铂金会员 Posts 1,827 Credits 5,154
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
....

Floor2 willsort Posted 2005-04-16 00:00
元老会员 Posts 1,512 Credits 4,432
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
Floor3 chenhui530 Posted 2005-04-16 00:00
高级用户 Posts 273 Credits 772
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.
Floor4 GOTOmsdos Posted 2005-04-16 00:00
铂金会员 Posts 1,827 Credits 5,154
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: ....
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023