Wednesday, January 4, 2017

windows - How to parse a directory recursively and MKLINK each file into a target path with the same tree structure

I have a directory a\ containing files and sub-directories that I want to copy into path b\ where instead of copying the files I want to perform a call to MKLINK on each file into the new path rather than performing an actual copy.



So if I have a directory:



Z:\a\file1.txt

Z:\a\file2.txt
Z:\a\some_path\file3.txt
Z:\a\some_path\file4.txt


And I copy links from path a\ to b\ the result will look like:



Z:\b\file1.txt           <<===>> z:\a\file1.txt
Z:\b\file2.txt <<===>> z:\a\file2.txt
Z:\b\some_path\file3.txt <<===>> z:\a\some_path\file3.txt

Z:\b\some_path\file4.txt <<===>> z:\a\some_path\file4.txt


The directory hierarchy is to be preserved as non-link folders in the event that the target directory does not have a matching folder structure. Note that only the files are links.



A successful test will succeed where Z:\b is an empty directory, Z:\b contains a folder Z:\b\some_path, and either previous tests but Z:\b my already contain files of the same name; conflicts are ignored and no link is created for them.



How can I do this using a batch file with no additional dependencies beyond what is available in a standard Windows 10 installation?

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...