- Joined
- Feb 12, 2012
- Messages
- 5
- Reaction score
- 0
I've searched Google and forums for days trying to figure out how to accomplish building a batch file that will parse a directory tree and copy 1 file from each subdirectory to a new folder.
I've got this as a lead:
https://www.pcreview.co.uk/forums/can-copy-file-multiple-folders-t1959548.html
and this...
http://stackoverflow.com/questions/1094921/dos-copy-the-first-file-in-a-directory
And I've tried this:
The pauses are present because I'm trying to figure out exactly what is occurring.
Within my "Master" directory there are about 250 subdirectories. I'd like to copy a single file from each subdirectory and put them in a new subdirectory called "Master-Copies", which should ultimately have 250 files. The subdirectories and files don't have spaces in their names, however I'd like to build that functionality into the batch file in case I ever run into this situation again. I'd like to copy the first file in each subdirectory. I know from reading other forums that the "FIRST" file is relative, but I'd like it to be the first file sorted by name.
I know I'm asking a lot, and hopefully some genius here can help out a kid new to programming.
Thanks!
I've got this as a lead:
https://www.pcreview.co.uk/forums/can-copy-file-multiple-folders-t1959548.html
and this...
http://stackoverflow.com/questions/1094921/dos-copy-the-first-file-in-a-directory
And I've tried this:
Code:
@ECHO OFF
CLS
PAUSE
FOR /R %%A in (C:\Users\Liam\Desktop\Master) DO (
COPY %%A C:\Users\Liam\Desktop\Master\Master-Copies\
GOTO :Exit
)
:Exit
Pause
The pauses are present because I'm trying to figure out exactly what is occurring.
Within my "Master" directory there are about 250 subdirectories. I'd like to copy a single file from each subdirectory and put them in a new subdirectory called "Master-Copies", which should ultimately have 250 files. The subdirectories and files don't have spaces in their names, however I'd like to build that functionality into the batch file in case I ever run into this situation again. I'd like to copy the first file in each subdirectory. I know from reading other forums that the "FIRST" file is relative, but I'd like it to be the first file sorted by name.
I know I'm asking a lot, and hopefully some genius here can help out a kid new to programming.
Thanks!