I need some assistence in the following task. I have a very large directory structure like below:
g:\documents\100
g:\documents\100\100001
g:\documents\100\100001\Incoming
g:\documents\100\100001\Workfiles
g:\documents\100\100001\Customer Files
g:\documents\100\100002
g:\documents\100\100002\Incoming
g:\documents\100\100002\Workfiles
g:\documents\100\100002\Customer Files
...
g:\documents\100\100999
g:\documents\100\100999\Incoming
g:\documents\100\100999\Workfiles
g:\documents\100\100999\Customer Files
...
g:\documents\101
g:\documents\101\101001
g:\documents\101\101001\Incoming
g:\documents\101\101001\Workfiles
g:\documents\101\101001\Customer Files
g:\documents\101\101002
g:\documents\101\101002\Incoming
g:\documents\101\101002\Workfiles
g:\documents\101\101002\Customer Files
...
g:\documents\101\101999
g:\documents\101\101999\Incoming
g:\documents\101\101999\Workfiles
g:\documents\101\101999\Customer Files
etc...
I want to move alle directory's Incoming and Workfiles into a new path e.q.: z:\documents with the same structure.
How can I iterate throug all the directory's and move the complete directory with the name is equal to Incoming or WorkFiles and create a structure that is the same to the old structure.
Resulting in:
g:\documents\100
g:\documents\100\100001
g:\documents\100\100001\Customer Files
g:\documents\100\100002
g:\documents\100\100002\Customer Files
...
g:\documents\100\100999
g:\documents\100\100999\Customer Files
z:\documents\100\100001\Incoming
z:\documents\100\100001\Workfiles
z:\documents\100\100002\Incoming
z:\documents\100\100002\Workfiles
...
z:\documents\100\100999\Incoming
z:\documents\100\100999\Workfiles
I want to do this in VB.NET or is there a syntax for robocopy that can do this job? other tools?
Thanks in advance!
You could do it by iterating the directory structure, and saving the paths that match WorkFiles & Incoming as the current found subdirectory. The other paths get scanned further, the matching ones are saved to process at a later stage.
After you got all matches, you then move the directories one by one to their new location. As the directories maintain their full path, it's easy enough to simply do a replace sourceDirectory with targetDirectory to get the new path. Then you check, if the parent path of this new path already exists, when not create it, and then move the directory from the source folder to the target folder
As an example, i wrote this one in Vb.net:
which would then get created and called in your program in the following way:
if you would rather see a list of matching items first, you could simply call the GetMatching method, that returns exactly that :)