Copy files from nested structure and rename by appending former directory name onto filename
Posted on 2014-01-05
I have thousands of files that are present in a series of directories like this:
I'm looking to copy all of the txt files to a common directory like this:
1) The directory name containing the files in question is unique, and we want to append that to the beginning of the filename as part of the copy...separated by an underscore.
2) We can select by extension - we want only the txt files and nothing else.
3) The original directory and files needs to stay intact.
4) There are a lot of large files that will be ignored.
5) There are no repetitions of the terminal directory names anywhere in the SourceFolder - they are truly unique. They start at 01 and go to roughly 1000000.
6) There are no repetitions of the file names (txt) anywhere in the SourceFolder - they are also truly unique.
7) However, the ignored files do have a generic name.
For now it would be acceptable to just do this as a single batch job, however...
Down the road I will want to be able to keep things up to date. Perhaps set a script to run once a day from 'Scheduled Tasks' or the like, and move newly written files from the source into the target, such that the target stays up to date as the source receives new files.
Expecting ~20,000 text files. Guaranteed to not bust 65,000 for a couple years.
Windows server 2003, 2008, or 2012.
Strong preference for a solution as a batch or an AutoIT script.