asked on
Batch file to copy folders/files with very long paths (how to automatically reduce path lengths?)
I created a batch file to synchronize the multiple "\packaged" folders in multiple directories
In other words, find and copy the following from my Google Drive:
J:\My Drive\Programming TestDept\Operations\\Localization\Drops\2021\20210816 Drop2c (summer)\drop20210816-drop2c\VP\Packaged
J:\My Drive\Programming TestDept\Operations\Localization\Drops\2021\20210911Drop3 (summer)\Van\Packaged
etc.
But the problem is that the paths created are beyond the supported 256 character length for Windows 10. :(
Here is the batch file:
@echo off
for /d /r "J:\My Drive\Development Enablement\Localization\Drops\2021" %%a in (packaged?) do (
if /i "%%~nxa"=="packaged" xcopy "%%a" "D:\_System\_loc\Sync\%%~pnxa\" /s/h/e/k/f/c
)
If I remove the "p" in %%~pnxa, the entire path is omitted, which is also not good because I want to at least preserve the path, starting with the date.
In other words, I would like the copied folders in the above examples to be copied like:
\20210816 Drop2c (summer)\drop20210816-drop2c\VP\Packaged
\20210911Drop3 (summer)\Van\Packaged
Not
\My Drive\Programming TestDept\Operations\Localization\Drops\2021\20210816 Drop2c (summer)\drop20210816-drop2c\VP\Packaged
Thank you for your advice. :)
ASKER
No, the path lengths are not consistent, but what is consistent is that I would like to always truncate the bold path section from the source:
\My Drive\Programming TestDept\Operations\Localization\Drops\2021\20210816 Drop2c (summer)\drop20210816-drop2c\VP\packaged
The bold section will always be consistent and I would like to not duplicate this unnecessary section on the destination, if possible.
ASKER
Hence, the need for a way to trim down the path length.
ASKER
And thanks to everyone else for your help.
More of an issue is how the script is supposed to identify the proper target folder.
There doesn't seem to be a consistent pattern here. You're going by the existence of a folder with the name "Packaged", and then in one instance want to copy it to a target determined from three levels up, the next one from two levels up.