Page 1 of 1

Copy / Move Maintaining Tree structure

Posted: 09 Nov 2021 02:12
by drgt
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.

Re: Copy / Move Maintaining Tree structure

Posted: 09 Nov 2021 08:08
by Squashman
Maybe use XCOPY with the /T and /E options.

Copy / Move Maintaining Tree structure

Posted: 09 Nov 2021 22:31
by drgt
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.

Copy / Move Maintaining Tree structure

Posted: 10 Nov 2021 00:15
by drgt
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"