How to copy a folder to target maintaining specified path tree (with the tree folders to be copied empty even if they contain files)
Example:
A dir command creates a text.log with an entry: "C:\user\desktop\FolderA\1\2"
It is asked to Copy / Move
C:\user\desktop\FolderA\1\2
to
C:\user\desktop\FolderB
NOT AS
C:\user\desktop\FolderB\2
BUT AS
C:\user\desktop\FolderB\1\2
C:\user\desktop\FolderA\1 might contain other subfolders (except "2") and / or files.
The C:\user\desktop\FolderB\1 should only contain the subfolder "2", not other folders or files.
Copy / Move Maintaining Tree structure
Moderator: DosItHelp
Re: Copy / Move Maintaining Tree structure
Maybe use XCOPY with the /T and /E options.
Copy / Move Maintaining Tree structure
xcopy "C:\user\desktop\FolderA\1\2" "C:\user\desktop\FolderB" /t /e copies nothing.
xcopy "C:\user\desktop\FolderA\1\" "C:\user\desktop\FolderB" /t /e copies folder 2 to target, not 1\2.
xcopy "C:\user\desktop\FolderA\" "C:\user\desktop\FolderB" /t /e copies unwanted subfolders of folderA too.
Remember we have to work with the "text.log" entries.
xcopy "C:\user\desktop\FolderA\1\" "C:\user\desktop\FolderB" /t /e copies folder 2 to target, not 1\2.
xcopy "C:\user\desktop\FolderA\" "C:\user\desktop\FolderB" /t /e copies unwanted subfolders of folderA too.
Remember we have to work with the "text.log" entries.
Copy / Move Maintaining Tree structure
The problem with this, I think, is that it must be specified where to start copying to.
I mean:
Does the system create <target path> append <source path> in which case the result will be
C:\user\desktop\FolderB\user\desktop\FolderA\1\2
That is not the desired result.
So, in addition to the "text.log" entry, in the sought batch it must be specified HOW MANY LEVELS to truncate from the entries path and append the rest.
In our case, truncate the "\user\desktop\FolderA" and create "1\2" under target.
In our case: C:\user\desktop\FolderB\1\2"
I mean:
Does the system create <target path> append <source path> in which case the result will be
C:\user\desktop\FolderB\user\desktop\FolderA\1\2
That is not the desired result.
So, in addition to the "text.log" entry, in the sought batch it must be specified HOW MANY LEVELS to truncate from the entries path and append the rest.
In our case, truncate the "\user\desktop\FolderA" and create "1\2" under target.
In our case: C:\user\desktop\FolderB\1\2"