Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively copy files that match a wildcard combination but not create the directory tree in DOS

I found that I can use xcopy /s to copy all files that match a wildcard combination in a folder to another location. But this command re-creates the folder structure. I do not want the tree. I need just the files dumped into the destination folder. There are no duplicate files in the source folder.

like image 766
BZ1 Avatar asked Sep 16 '11 06:09

BZ1


People also ask

Does xcopy create directories?

If source is a directory or contains wildcards and destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether destination is a file or a directory.

What is the DOS command to copy a directory?

To copy a directory in MS-DOS, use the xcopy command.

What is xcopy command in MS-DOS?

In computing, XCOPY is a command used on IBM PC DOS, MS-DOS, IBM OS/2, Microsoft Windows, FreeDOS, ReactOS, and related operating systems for copying multiple files or entire directory trees from one directory to another and for copying files across a network.

Is xcopy recursive?

The xcopy command is very similar to the copy command but it handles recursion and has many other options mainly related to recursion.


2 Answers

You can use for command:

for /R %%x in (*.cpp) do copy "%%x" "c:\dest\"

If you want to run it directly from command prompt (not from a batch file) use %x instead of %%x.

like image 119
Sergey Podobry Avatar answered Sep 21 '22 22:09

Sergey Podobry


For your purpose, instead of using xcopy you should use robocopy:

http://en.wikipedia.org/wiki/Robocopy

http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

like image 24
gingo Avatar answered Sep 21 '22 22:09

gingo