Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Backup and restore file timestamps

Dec
17
0
So I came across a script by someone which succeeds in backing up and restoring modification dates only but not creation. I'd paste the scripts here but this website won't let me for some reason.

Is there a script in TCC LE that'll copy both the timestamps of every file in a given folder and then restore it should these timestamps ever change because a file got accidentally modified etc.?

Thanks.
 
How about something like this. It's not too sophisticated but it should work or at least give you a starting point. It handles both the modify and the creation timestamps.

First batch file would save the existing timestamps to an INI file. It operates on the current working directory (and descends into subfolders).
Code:
@echo off

for /r %%a in (*) do (
  echo %%a
  set _i=%@iniwrite[c:\fileinfo.ini,,%%a,%@filedate["%%a",c,s],%@filetime["%%a",c,s],%@filedate["%%a",w,s],%@filetime["%%a",w,s]]
)

And a second batch file would read through the INI file and update the timestamps on the files.
Code:
@echo off

for /r %%a in (*) do (
  set _s=%@iniread[c:\fileinfo.ini,,%%a]
 
  iff "%_s" ne "" .and. exist "%%a" then
    echo %%a
    touch /q /dc%@word[",",0,%_s] /tc%@word[",",1,%_s] "%%a"
    touch /q /dw%@word[",",2,%_s] /tw%@word[",",3,%_s] "%%a"
  endiff
)
 
Thanks Rod, that worked. What do I edit to disable processing of subfolders? I rarely need to change timestamps of subdirs.
Also the bat file can't be opened with regular CMD and it's not really a hassle to open TCC then drop the bat in but I was wondering if this is what everybody else does? .bat files don't seem to have a "Open With" option in Explorer.

Thanks for the help and disregard/delete my double-post. Nothing happened when I pressed post reply so I assumed post didn't go thru and tried again. I guess it does work.
 
If you work in TCC, you can use the exclusion ranges (see Help -> Ranges -> Exclusion Ranges). In a Microsoft command processor you can get a full catalog of all possible files, and manually edit out the unnecessaries.
 
To disable processing of subfolders just remove the /R from the for command in the first example above.
 
Thanks Rod, that worked. What do I edit to disable processing of subfolders? I rarely need to change timestamps of subdirs.
As Charles mentioned, just remove the /R switch from the FOR command.

Also the bat file can't be opened with regular CMD and it's not really a hassle to open TCC then drop the bat in but I was wondering if this is what everybody else does? .bat files don't seem to have a "Open With" option in Explorer.
Correct, this batch file uses TC specific functions/features and won't work in CMD. Personally I never run batch files by clicking them in Explorer. I am a command line junkie and run them manually from the prompt.

But if you want to run them from Explorer, you should check out the TCCBATCH.CMD file that I assume is included in TCC LE as it is with the full Take Command product. I would adjust it so it only associates BTM files though. I use the BTM extension for batch files that require TCC, and CMD/BAT extension for ones that are compatible with cmd.exe. I don't like TCC running all CMD/BAT files by default because it is not always compatible with cmd.exe.
 
Thanks CHarles G and Rod.

I noticed that this script processes only files and not folders, can the timestamps of folders also be saved/restored?
 
rem first batch file
@echo off

for /a: /r %%a in (*) do (
echo %%a
set _i=%@iniwrite[c:\fileinfo.ini,,%%a,%@filedate["%%a",c,s],%@filetime["%%a",c,s],%@filedate["%%a",w,s],%@filetime["%%a",w,s],[EMAIL]%@attrib[%%a[/EMAIL]]]
)

rem second batch file
@echo off
for /r %%a in (*) do (
set _s=%@iniread[c:\fileinfo.ini,,%%a,%%f_Attrs]
iff "%_s" ne "" .and. exist "%%a" then
echo %%a
touch /q /dc%@word[",",0,%_s] /tc%@word[",",1,%_s] "%%a"
touch /q /dw%@word[",",2,%_s] /tw%@word[",",3,%_s] "%%a"
endiff
)

Not tested - might need additional testing..... for folders....
 
Hmm... I was just looking at my batch file examples again and I'm not sure why I have an "s" for a third parameter in the @FILEDATE/@FILETIME functions.
 
Merry Xmas.

Charles, your batch to save timestamps produced a lot of "cannot find file" errors.
Code:
[C:\test]"C:\Documents and Settings\Admin\Desktop\timestamp save1.bat"
C:\test\.
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\"
C:\test\..
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\"
C:\test\a
C:\test\a\.
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\"
C:\test\a\..
C:\test\a\b
C:\test\a\b\.
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\b\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\b\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\b\"
TCC: (Sys) C:\Documents and Settings\Admin\Desktop\timestamp save1.bat [6]  The system cannot find the file specified.
 "C:\test\a\b\"
C:\test\a\b\..

[C:\test]

And your timestamp restore batch didn't restore the timestamps.

Contents of fileinfo:
Code:
[]
C:\test\.=,,,,____D__________
C:\test\..=,,,,_HS_D__________
C:\test\a=01/01/00,00:00:00,01/01/10,00:00:00,___AD__________
C:\test\a\.=,,,,___AD__________
C:\test\a\..=12/26/13,02:26:56,12/26/13,02:28:16,____D__________
C:\test\a\b=01/01/12,02:28:18,03/01/13,02:28:18,___AD__________
C:\test\a\b\.=,,,,___AD__________
C:\test\a\b\..=01/01/00,00:00:00,01/01/10,00:00:00,___AD__________

Rod, what does the "s" do?
 
In @filedate[] the s is an invalid date format character which happens to be ignored.
In @filetime[] the s specifies that 1s resolution is requested (instead of the default 1min resolution) on file times.
Ah ok, I must have copied the syntax from @filetime and used it for @filedate.
 

Similar threads

Back
Top