I wrote a VBscript that checks path length and calls subst
, as soon as a certain threshold is reached. These calls are stacked on each other so that in the middle of a recursion, this layout exists:
C:\a\very\long\path
subst K: "C:\a\very\long\path"
K:\another\very\long\path
subst L: "K:\another\very\long\path"
L:\yet\another\very\long\path
subst M: "L:\yet\another\very\long\path"
xcopy M:\*.* "D:\target"
This way with each level of subst, a shorter path is generated. It also means, that you must copy your folders sequentially, to be able check for long paths before you issue the copy command.
Once all files in a folder are copied, the recursion does jump back one level (subst /d
), freeing up one drive letter.
Using 4-5 drive letters, that subst each other when the path gets to deep I had been able to copy paths that had lengths waaaaay over the MAX_PATH limit.
EDIT
This describes the general procedure of doing it with subst. How you do it depends on your needs, I always used that little subst trick in a minimal, "solves this single problem" way.
For example, copying to an equally deep target path means you need another stack of subst'ed drive letters.
Unpacking all .zip files within a single, deeply nested directory structure may require only on stack, but you need to shorten the threshold a bit to account for folders in the .zip, etc.