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-02 06:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to batch copy specified files under a folder?? View 2,015 Replies 9
Original Poster Posted 2006-10-08 23:47 ·  中国 河南 安阳 电信
新手上路
Credits 12
Posts 4
Joined 2006-10-08 22:37
19-year member
UID 64963
Status Offline
There was someone who asked this question before. But I didn't understand the content in the post very well.

Original post (http://www.cn-dos.net/forum/viewthread.php?tid=20648)


I want to ask.
For example, there are 10,000.txt documents in folder A under drive C.
The file names are a00001 - a09999 (all are.txt documents, not folders)

And I have a directory. About 1,000 of them are the files I need from A.
For example, they are
C:\a\a00001.txt
C:\a\a00602.txt
C:\a\a00203.txt
C:\a\a00007.txt
...
C:\a\a04203.txt
C:\a\a04303.txt
etc. with irregular names.
I want to ask, how to copy the documents in C:\a (note again, there are no subfolders in A)
I want to copy the documents in the directory to another folder such as C:\b?

The result of my search on the Internet is to run something like XCOPY under DOS. But it's not very clear.
May I ask what methods are there? If there are, please explain clearly and in detail, thank you.

Or send an email to to7m8@126.com. thx!

[ Last edited by newstart on 2006-10-9 at 05:50 ]
Floor 2 Posted 2006-10-08 23:53 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Please specify your DOS version, such as whether it is pure DOS or CMD under Windows. If it is pure DOS, then which version is it.

Also, are you talking about files or folders? a00001-a09999 looks like a folder name at first glance. "Their names are a00003..a004234..a032043... and other irregular names." In this case, are the names of these files still the same as the file names under A?
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-10-09 00:14 ·  中国 河南 安阳 电信
新手上路
Credits 12
Posts 4
Joined 2006-10-08 22:37
19-year member
UID 64963
Status Offline
1. DOS is the cmd under xp
2. a00001 - a09999 are all.txt documents
3. And the directory I need is a00003..a004234..a032043... and other irregular names, (all are document names)
4. I need to copy 1000 documents in the directory to another folder. If I find them according to the directory, it will be quite complicated. So I come to ask for advice!~! Thank you,
Floor 4 Posted 2006-10-09 00:32 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
Enter "help xcopy" in CMD first
Floor 5 Posted 2006-10-09 00:35 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The code written by Master Climbing is already powerful enough. If it were me, I would also come up with a similar code for you. And you said you don't quite understand it, then there's no way.

Let me give you a hint: You need to use the extended usage of the for statement, extract the file name, in the format of for %%i in () do echo %%~ni.

Looking back at your description, you said "And the directory I need is names like a00003..a004234..a032043... which are irregular, (all are document names)". Whether a00003, etc. are files or folders confuses me again, sweat.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-10-09 00:36 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
The LZ's question doesn't seem to be very clear... (My comprehension ability is poor)
~~~~好好学习
天天向上~~~~
Floor 7 Posted 2006-10-09 05:48 ·  中国 河南 安阳 联通
新手上路
Credits 12
Posts 4
Joined 2006-10-08 22:37
19-year member
UID 64963
Status Offline
Moderator namejm, the directory I mentioned is the address where the documents (.txt) are stored.

For example:
C:\a\a00001.txt
C:\a\a00002.txt
C:\a\a00003.txt
C:\a\a00007.txt
C:\a\a04303.txt
..
...

Unfortunately, my expression ability is not professional, which makes everyone laugh.

I have 10,000 .txt documents in folder A under drive C,
The file names are a00001.txt - a09999.txt (all are .txt documents, not folders)

And I have a directory. There are about 1,000, which are the files I need in A,
For example, they are
C:\a\a00001.txt
C:\a\a00602.txt
C:\a\a00203.txt
C:\a\a00007.txt
...
C:\a\a04203.txt
C:\a\a04303.txt
and other irregular names.
I want to ask, how to copy the documents in C:\a (note again, there are no subfolders in A)
I want to copy the documents in the directory to another folder, such as C:\b?


The following is what I tried using the one written by Big Climbing,
The result prompted me that "There should not be %%i at this time


@echo off
::C:\b
set dst=C:\a

for /F "tokens=*" %%i in (list.txt) do md %dst%%%~pi && copy /y %%i %dst%%%~pi && echo success copy %%i

I want to ask. 1, Is the above statement pasted all at once and pressed Enter on the right of cmd c:?
2, Is list.txt placed under c:\?
3, The one in the form of a00234 is a .txt document, not a folder!

[ Last edited by newstart on 2006-10-9 at 05:54 ]
Floor 8 Posted 2006-10-09 11:43 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The problem of the original poster already belongs to the scope of CMD batch processing. It is suggested to post it to DOS Batch & Script Technology (Batch Processing Room).

Answer part of the questions in "Building 7":
1. The code of climbing cannot be run in the CMD command window. If you want to run it sentence by sentence, you should change all double percent signs to single percent signs;
2. list.txt should be placed in the same directory as this batch processing program, or after placing it in any directory, change (list.txt) to the format of (path\list.txt).

In addition, there is a key part of your modified description that I still don't understand: "And I have a directory. About 1000, which are the files I need in A". 1000 directories? That's scary. After looking at your subsequent examples, it should mean 1000 records? Let's姑且 according to my understanding, take your problem as: There are 10,000 text files under c:\a, and you only want to copy 1,000 of them. The absolute paths of these 1,000 files have been extracted by you and placed in a text called list.txt. Now you want to copy these 1,000 text files to c:\b. For this specific requirement, I wrote a piece of code, please test:

@echo off
:: The content in list.txt is the list of absolute paths of the documents you are about to copy, one record per line
:: list.txt should be in the same directory as this script program
if not exist c:\b md c:\
for /f "tokens=*" %%i in (list.txt) do copy "%%i" c:\b
start c:\b
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-10-09 12:26 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

The original poster still didn't describe the problem clearly, which made the moderator anxious~~

Hehe~~

It is suggested that when asking a question, try to describe the problem in detail~~
Floor 10 Posted 2006-10-09 20:17 ·  中国 河南 安阳 电信
新手上路
Credits 12
Posts 4
Joined 2006-10-08 22:37
19-year member
UID 64963
Status Offline
Thanks to user namejm for the answer on floor 8.

You have understood my meaning *_^

I'm in cmd. Changed your program to a %

Result............

...............

............... Hey.

Finally succeeded! Thank you all! :P:P:P

[ Last edited by newstart on 2006-10-9 at 20:23 ]
Forum Jump: