General discussion


Copy only select files from multiple sub-directories using xcopy

By sporzondek ·
Is there a way to copy only select files that reside in sub-directories using the xcopy command in a batch file? Example: text file has list of 2500+images that are in multiple sub-directories under one main directory. The entire library has over 500,000 images so it is imperative to only copy what is needed. Is there a way to do this in Windows using xcopy in a batch file?

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

I'm sure there is

by seanferd In reply to Copy only select files fr ...

but you'd have to define which files you actually want, which, in the end, may involve listing each file individually.

I'm not sure I see a way to pipe a list from a text file directly to the xcopy command. You might have to write a batch file to do this using For...In...Do...

Ah, here's an example:



On the other hand, if you had a text file of all the files in the directories that you <i>don't</i> want to copy, the xcopy /exclude would work well.

I've had a look at the utility xxcopy (which is a nice xcopy replacement), but it lacks this functionality as well.

Good luck.

If these files would tend to group themselves in the Explorer GUI (choose Details View) by sorting by date, name, etc. by clicking on the detail columns, then just copying from Explorer may be faster

Collapse -

It's a bit more involved...

by sporzondek In reply to I'm sure there is

I have the image id numbers in a text file. I just need to extract them and copy to a repository folder. (Image ids are database references, so there is no filepath information that is attached. I have to include that in the text file, but do not know exactly which sub folder each image is in.) from my research findings, I do not see a way to do this easy in windows. I basically need to find a way to searh directories for a specific id, find that id, then copy to destination folder. Any suggestions?

Collapse -

use the directory command

The command
"dir drive\path\filename.ext /s"
will list all the files in the specified directory and all subdirectories.

To send the output to a file, use the redirect symbol ">".

Use the /b switch to save only the filename.ext

Your command would look something like:

[pre]dir d:\path\file*.ext /s /b > destfile.ext[/pre]

Back to Software Forum
3 total posts (Page 1 of 1)  

Software Forums