mirror directory tree and preserve directory timestamp

Aug 2, 2011
258
4
Berlin, Germany
I want to mirror a directory tree to different drive/location.
I tried COPYand SYNC but both create the new directories with the actual date&time.
Is there a way to preserve the date&time of the original directory ?
Especially with SYNC I hoped that it would be possible.
For me the timestamp of a directory is a useful information and I don't want to lose it.

btw:
I accidentally used a wrong syntax for @FILES:
Code:
echo %@files[ /s /a:d *.*]
This one stalls and doesn't come back to the prompt.
Of course it should be
Code:
echo %@files[ /s *.*,d]


and even more to complain :p:
It would be nice if SYNC would report the copied directories, too
Code:
>sync /s /a:d .\share-backups c:\temp\xxx\share-backups
SYNC: \\company.net\Net-BER\DV\Share\!w2kadm\share-backups => C:\temp\xxx\share-backups
    0 files copied
SYNC: C:\temp\xxx\share-backups => \\company.net\Net-BER\DV\Share\!w2kadm\share-backups
    0 files copied
 
May 31, 2008
382
2
I don't think that COPY has an option to preserve directory timestamps. So I *think* that you need to COPY the whole tree first, then set directory timestamps with TOUCH. Start from leaf directories and move upwards through the tree, because otherwise Windows resets the write date of a parent directory when you touch the dates of the folders it contains. Roughly coding,
Code:
DIR /A:D /S /F SourceTreeTop\ > DirList.txt
then sort DirList.txt in reverse order and
DO SourceDir in @dirlist.txt (TOUCH /A:D /R:w"%SourceDir%" "%@TargetDir[%SourceDir%]")
where your used-defined function TargetDir maps each source directory path into its corresponding target directory path.
TotalCommander, a file manager program, has an option to copy trees and preserve directory dates.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
The reason directory timestamps are not copied is that only files are copied, but directories have to be created new on the target system. When you copy a file, in the various file systems which support long file names in Windows, by default the target file's creation date and access date are when the copy is made, and its modification date is copied from the source. Cf. POSIX - the default modification date of the target is the time the copy is made (I always hated that, and always used the option of the cp command which copies the source's modification date to the target. However, every time another file is copied to the target directory, it changes the content of that special file, so logically its modification time is new.

However, you can use the TOUCH command to make the modification dates of each target directory the same as the corresponding source directory in the manner below:

copy /s xxx\ yyy\
for /a:d /r yyy\ %d in (*) touch /a:d /r %@replace[yyy\,xxx\,%d] %d

BEWARE! NOT TESTED! Of particular issue is the possibility that directory names may need to be quoted...
 
Aug 2, 2011
258
4
Berlin, Germany
Stefano and Steve, thank you for your explanation and sample code.
But somehow I'm not so excited with the TOUCH-solution (for ~ 50000 dirs).
It's a pity, but I will fall back on ROBOCOPY.
 
Similar threads
Thread starter Title Forum Replies Date
fishman@panix.com HELP!! I just updated to Version 28 and as usual I cannot make extended directory search work. Support 2
D How to use multi-line DO to loop through first level directory names Support 5
D ParentDirectory does not update directory history Support 6
samintz CDD to non-existent directory hangs Support 2
gworley rd (Remove Directory) gives interesting error: Support 2
D Directory History Window with wildcard search Support 3
D How to? Skip removing directory (RMDIR) without error message Support 2
gentzel Directory stack empty when running TCEXIT? Support 9
vefatica Disable extended directory searches (completely)? Support 8
M WAD "Pictures" directory is empty in TCC but not in CMD or Explorer Support 4
G Local Directory Corruption Support 11
Jay Sage Directory Alias Access to FTP Servers Support 2
Joe Caverly DIRectory Colorization in v25 Help File Support 0
K copy changing destination current directory Support 1
thorntonpg option /u not working The directory name is invalid Support 5
J built in file explorer - how do i go back "up" the directory? Support 2
vefatica Extended directory searches? Support 6
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
A Installer /extract: extracts into current directory if target not exists Support 12
Charles Dye Ctrl-Shift-Up doesn't update directory history Support 1
G Extended directory search not working Support 4
CWBillow Editing in the root directory of windows 10 Support 6
D Directory stack empty Support 1
J directory or folder to start in Support 2
M How to unlock a directory Support 1
Alpengreis Fixed TCMD FileExplorer Start-Directory problem Support 4
R V19 - At startup, TCC save directory in the directory history list Support 2
C Touch command — I Need to touch matching files in another directory. Support 5
nickles Move takecommand.18.0.key location to installation directory Support 4
fishman@panix.com Extended Directory Searches are not working for me in CDD Support 9
vefatica TCMD's current directory? Support 4
J How to set working directory Support 10
nickles How to? Follow a JUNCTION type directory link Support 9
Steve Pitts WAD Strange output from DEL of a non-existent directory Support 7
I tab completion with directory commands Support 7
vefatica Start-up directory for new tabs? Support 7
cgunhouse Problem with CALL and Directory Aliases in V17 Support 9
vefatica FFIND /S, find directory with specified name? Support 7
David Wilbanks How to make new tab open in same directory as previous tab? Support 4
H WAD Wild Card in Directory @shfolder[25] acting differently Support 3
M How to? List path getting short file and directory names... Support 10
A How to? Can't change directory ("cd") into system hidden files Support 13
mfarah How to? So I want a custom directory for the plugins... Support 16
D Why doesn't ffind find directory? Support 3
T dir /h error in empty directory Support 22
S directory history locks up TCC Support 3
B Why Does @GETDIR Repeat Selected Directory Name In Returned Value Support 7
ed neff How to? exit TCC/Take Command to a new directory Support 10
Jake Default directory Support 3
Frank ZIP: howto store directory in the zip-file Support 20

Similar threads