How to? Copy DIRs with attributes ...

Jan 12, 2014
386
7
Switzerland, SO
I have the following scenario:

dir-structure1.png


As you can see, the Directories have attributes too.

I have no problem to copy the whole structure with external xcopy or robocopy ...

Code:
xcopy d:\_Tests\Test-DIR-Structure-for-BAK-CHK v:\_Temp\test /e /h /k

robocopy d:\_Tests\Test-DIR-Structure-for-BAK-CHK v:\_Temp\test /e
The result in target is the same as in source.

BUT I HAVE a problem to make this with the internal copy command! I tried ...

Code:
copy /h /k /s d:\_Tests\Test-DIR-Structure-for-BAK-CHK v:\_Temp\test
Then the result is this ...

dir-structure2.png


How can I preserve the directory attributes with the internal copy command?

Greetings!
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,202
72
Albuquerque, NM
prospero.unm.edu
COPY doesn't do that, as you've already shown. I think you would have to do it as two steps: copy the directory structure first, then go back and copy the attributes. Possibly by redirecting the output of ATTRIB /A:D /S to a file, then using SED or the like to massage that file into a batch file?
 
  • Like
Reactions: Alpengreis
Jan 12, 2014
386
7
Switzerland, SO
All right, thank you!

It's not a MUST to use the internal copy for such processes - I was just not completely sure if it's "direct" possible anyway.

However: I know now that I would have to use a workaround as you suggested above.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
There's also COPYDIR. It also doesn't copy attributes. I was a little surprised to find that Explorer does copy the attributes of directories (copy/paste, drag/drop). I wonder whether that's the default for SHFileOperation and how easily Rex could add it to COPYDIR (don't know if COPYDIR uses SHFileOperation). You could make a suggestion out of it.