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-04 22:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can DOS only copy files inside the subdirectories of a folder? View 1,575 Replies 9
Original Poster Posted 2007-05-23 23:56 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 61
Joined 2007-04-14 09:23
19-year member
UID 85115
Gender Male
Status Offline
There is a folder A. There are quite a few subfolders inside it. Can DOS complete the task of only copying all the files in folder A without including the subfolders (that is, excluding the subfolders)? If it can, how to do it? Thanks in advance!
Floor 2 Posted 2007-05-24 04:06 ·  中国 重庆 沙坪坝区 电信
中级用户
★★
金牌会员
Credits 315
Posts 152
Joined 2007-01-25 23:55
19-year member
UID 77669
Gender Male
Status Offline
copy A\*.* 2\
Should be okay```It won't copy the contents of subdirectories in directory A
Change the path yourself`

[ Last edited by fengzi on 2007-5-24 at 04:35 AM ]
Floor 3 Posted 2007-05-24 06:19 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 61
Joined 2007-04-14 09:23
19-year member
UID 85115
Gender Male
Status Offline
Originally posted by fengzi at 2007-5-24 04:06 AM:
copy A\*.* 2\
It should work```It won't copy the contents of subdirectories in directory A
Change the path yourself`

[ Last edited by fengzi on 2007-5-24 at 04:35 AM ]

What is the 2\ at the end?
Actually, I want to copy all files inside subdirectory A. But I need to exclude the subfolders in A.

For example: There are subdirectories B, C, ..., F in A. I want to copy all files in B to F to G with just one command, and exclude subdirectories B, C, ..., F.

[ Last edited by nbic on 2007-5-24 at 06:24 AM ]
Floor 4 Posted 2007-05-24 10:12 ·  中国 广东 佛山 电信
高级用户
★★
我思故我在
Credits 512
Posts 228
Joined 2007-01-21 10:31
19-year member
UID 77225
Gender Male
Status Offline
Just copy the folder directly. For example, copy A:\B G:
copy will exclude the subfolders in folder B
Floor 5 Posted 2007-05-24 10:38 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 61
Joined 2007-04-14 09:23
19-year member
UID 85115
Gender Male
Status Offline
Originally posted by qinbuer at 2007-5-24 10:12 AM:
Just copy the entire folder, for example, copy A:\B G:
copy will exclude subfolders within folder B

This only works if there are no subfolders in B. The problem is, when the directory tree is long, do we have to write out each path? That would be very cumbersome. Moreover, the number of subfolders in B can change. If we have to write the paths, it would be even more difficult.
Floor 6 Posted 2007-05-24 10:42 ·  中国 广东 佛山 电信
高级用户
★★
我思故我在
Credits 512
Posts 228
Joined 2007-01-21 10:31
19-year member
UID 77225
Gender Male
Status Offline
Having a folder is also okay. For example, there is a test folder and a test.txt text file under folder B. Copying A:\b will only copy the test.txt text file. You should try it before asking questions.
Floor 7 Posted 2007-05-24 11:57 ·  中国 广东 深圳 电信
初级用户
★★
Credits 135
Posts 61
Joined 2007-04-14 09:23
19-year member
UID 85115
Gender Male
Status Offline
Originally posted by qinbuer at 2007-5-24 10:42 AM:
It's okay to have a folder. For example, there is a folder B and a text file test.txt. Copying A:\b will only copy the text file test.txt. You should try it before asking.

I guess you still don't understand what I mean. It's not that I haven't tried, but that I have tried it long ago.

For example, there is a folder test and a text file test.txt under folder B. Can you copy A:\b and then copy all the files in B, excluding the folder test? The requirement is not to extend the path to the subfolder test.
Floor 8 Posted 2007-05-24 12:54 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
for /r D:\xy %%a in (*.*) do xcopy %%a e:\xy\
Floor 9 Posted 2007-05-24 12:57 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
You can use dir /a-d to find the path of COPY, excluding directories

[ Last edited by zhoushijay on 2007-5-24 at 12:58 PM ]
你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a>
Floor 10 Posted 2007-06-13 00:19 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Files and folders with filenames containing spaces were not handled.
Copy the files in the subfolders in the d:\a folder to e:\abc.
The general idea is like this, not tested....
@echo off
for /f %%i in ('dir/ad/b d:\a') call :lis %%i
goto :eof
:lis
for /r %1 %%j in (*.*) do xcopy/y/e %%j e:\abc\
goto :eof
Forum Jump: