![]() |
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-08-04 23:50 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » Can DOS only copy files inside the subdirectories of a folder? |
| Printable Version 1,577 / 9 |
| Floor1 nbic | Posted 2007-05-23 23:56 |
| 初级用户 Posts 61 Credits 135 | |
|
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!
|
|
| Floor2 fengzi | Posted 2007-05-24 04:06 |
| 中级用户 Posts 152 Credits 315 | |
|
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 ] |
|
| Floor3 nbic | Posted 2007-05-24 06:19 |
| 初级用户 Posts 61 Credits 135 | |
Originally posted by fengzi at 2007-5-24 04:06 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 ] |
|
| Floor4 qinbuer | Posted 2007-05-24 10:12 |
| 高级用户 Posts 228 Credits 512 | |
|
Just copy the folder directly. For example, copy A:\B G:
copy will exclude the subfolders in folder B |
|
| Floor5 nbic | Posted 2007-05-24 10:38 |
| 初级用户 Posts 61 Credits 135 | |
Originally posted by qinbuer at 2007-5-24 10:12 AM: 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. |
|
| Floor6 qinbuer | Posted 2007-05-24 10:42 |
| 高级用户 Posts 228 Credits 512 | |
|
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.
|
|
| Floor7 nbic | Posted 2007-05-24 11:57 |
| 初级用户 Posts 61 Credits 135 | |
Originally posted by qinbuer at 2007-5-24 10:42 AM: 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. |
|
| Floor8 terse | Posted 2007-05-24 12:54 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
for /r D:\xy %%a in (*.*) do xcopy %%a e:\xy\
|
|
| Floor9 zhoushijay | Posted 2007-05-24 12:57 |
| 高级用户 Posts 375 Credits 845 | |
|
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 ] |
|
| Floor10 26933062 | Posted 2007-06-13 00:19 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
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 |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |