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-01 11:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch script for finding files View 1,874 Replies 6
Original Poster Posted 2004-12-16 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 186
Posts 36
Joined 2003-10-02 00:00
22-year member
UID 10609
Gender Male
Status Offline
Known: In n:\aaaa\ there are several files such as a.exe, b.exe, c.bat... where N = C:, D:, E:... M:

To find: The batch to copy the files in the aaaa folder to C:\.

This noob is not familiar with loop statements, so he has to search disk by disk, which is too troublesome. Please, great master, write a simple one.

Floor 2 Posted 2004-12-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 lin8197:
A simplified program, ignoring many details and not tested, you try it first, if there are any problems, discuss them.
@echo off
if == %0 c d e f g h i j k l m
:loop
if == goto end
for %%f in (a.exe b.exe c.bat) do if exist %1:\aaaa\%%f copy %1:\aaaa\%%f c:\
shift
goto loop
:end

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2004-12-16 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 186
Posts 36
Joined 2003-10-02 00:00
22-year member
UID 10609
Gender Male
Status Offline
Thanks for the explanation. I tried it, it works under XP, but not under DOS and 98. I mainly use it under DOS, please help to modify it
Floor 4 Posted 2004-12-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 lin8197: Please first tell me what the problem is (error message), then tell me your usage requirements (such as using on a specific model or a series of models). In short, it is important to describe it simply and accurately. The problems I think of may be file name problems (containing spaces), disk drive letter problems (may encounter an unready CD-ROM), is your problem one of these?
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2004-12-16 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 186
Posts 36
Joined 2003-10-02 00:00
22-year member
UID 10609
Gender Male
Status Offline
d:\>abc
0 file(s) copied
0 file(s) copied
0 file(s) copied

CDR101: Not ready reading drive GI tried it in the virtual machine, the above is the prompt
Floor 6 Posted 2004-12-16 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 186
Posts 36
Joined 2003-10-02 00:00
22-year member
UID 10609
Gender Male
Status Offline
By the way, I didn't make it clear. I need to use it on different machines, and the number of partitions on each machine is different.
Floor 7 Posted 2004-12-17 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 lin8197:
It seems that the first problem encountered is the judgment of non-hard disk drive letters. Because when 98 and DOS use if exist to access an unprepared drive, an error message will appear, while XP and 2000 ignore this error.
To solve it, first ensure that the drive letter list is as small as possible. I don't know how your c~m is determined. If possible, try to narrow its range as much as possible. In addition, a check should be made for whether each drive letter is ready. The simplest way is to use the third-party tool dready.com, which comes from the hosrt32 tool kit. The usage is as follows (the program has not been tested either). If your environment is not suitable for using the third-party tool, you can dynamically generate a script and then use debug to call the DOS interrupt to get a similar effect.
In addition, if used below DOS 6.xx, please pay attention to the 8.3 filename convention, otherwise some unexpected errors will occur.
@echo off
if == %0 $ c d e f g h i j k l m
:loop
shift
if == goto end
dready %1
if errorlevel 2 goto loop
for %%f in (a.exe b.exe c.bat) do if exist %1:\aaaa\%%f copy %1:\aaaa\%%f c:\
goto loop
:end
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: