Page 1 of 1

[Solved] back up and restore the modified date

Posted: 05 May 2016 09:02
by xnmp
Hi, i want to back up and restore the modified date, created date of files (based on the filepath )
(I'm going to edit some files, and restore their date after editing )
for example i run "backup" and the script store the data into a text file like this

Code: Select all

 file | date modified | date created
e:\test1\a.jpg  | 5/3/2016 4:29:29 PM  | 5/3/2016 4:32:52 PM
e:\test2\b.jpg  | 5/3/2016 11:25:52 AM | 5/3/2016 11:25:52 AM
(or any other forms )
Then i run "restore" the script would read the text file and restore the modified date, created date of listed files
Any help would be much appreciated
Thank you

Re: back up and restore the modified date

Posted: 05 May 2016 09:11
by RalphM
If you're using backupto for the backup as well as for the restore with preserve dates you shouldn't need to change the dates after the restore.

Re: back up and restore the modified date

Posted: 05 May 2016 09:23
by xnmp
RalphM wrote:If you're using backupto for the backup as well as for the restore with preserve dates you shouldn't need to change the dates after the restore.
Thank you very much ,actually i know it
I'm going to edit some files, and restore their date after editing

Re: back up and restore the modified date

Posted: 05 May 2016 10:01
by highend

Code: Select all

"_Initialize"
    global $logFile = "<curpath>\dates.txt";

"Backup file dates..."
    global $logFile;
    $logContent = "";
    foreach($file, <get SelectedItemsPathNames |>) {
        if (exists($file) != 1) { continue; }
        $created  = property("#date.c", $file);
        $modified = property("#date.m", $file);
        $logContent = $logContent . "$file|$created|$modified<crlf>";
    }
    writefile($logFile, $logContent);

"Restore file dates..."
    global $logFile;
    $logContent = readfile($logFile);
    foreach($line, $logContent, <crlf>) {
        $file     = gettoken($line, 1, "|");
        $created  = gettoken($line, 2, "|");
        $modified = gettoken($line, 3, "|");
        if (exists($file) != 1) { continue; }
        timestamp "c", $created, $file;
        timestamp "m", $modified, $file;
    }

Re: back up and restore the modified date

Posted: 05 May 2016 10:03
by xnmp
Omg you are so quick
I'll try it ,thank you very much ,highend

Re: back up and restore the modified date

Posted: 05 May 2016 10:25
by xnmp
Hi highend,
Thank you very much for the help, ireally appreciate your effort
i 've just tried it , the modified and created date in list is differrent from the date propertiers in xyplorer
here is the result in text file

Code: Select all

E:\Temp\X3HA_01_01_01.unity3d|5/5/2016 3:11:40 PM|5/11/2015 8:35:13 AM
E:\Temp\X3HA_01_01_02.unity3d|5/5/2016 3:11:40 PM|5/11/2015 8:35:13 AM
E:\Temp\X3HH_01_01_00.unity3d|5/5/2016 3:11:40 PM|5/11/2015 8:35:13 AM
E:\Temp\X3HH_01_01_01.unity3d|5/5/2016 3:11:40 PM|5/11/2015 8:35:13 AM
E:\Temp\Yaz.unity3d|5/5/2016 3:11:40 PM|5/11/2015 8:35:13 AM
And here is what i copied from xyplorer propertiers (created/modified like in your script),the order is the same with the list file

Code: Select all

  (E:\Temp\X3HA_01_01_01.unity3d) 5/5/2016 3:11:40 PM | 5/11/2015 8:35:13 AM
  (E:\Temp\X3HA_01_01_02.unity3d) 5/5/2016 3:11:40 PM | 5/11/2015 8:35:04 AM
 (E:\Temp\X3HH_01_01_00.unity3) 4/29/2016 3:22:05 PM | 5/11/2015 8:34:36 AM
(E:\Temp\X3HH_01_01_01.unity3d) 5/5/2016 3:11:40 PM | 5/11/2015 8:35:07 AM  
 (E:\Temp\Yaz.unity3d) 5/5/2016 3:14:41 PM | 3/26/2015 10:51:56 PM
i have no idea why it 's so different, especially in the last line
Again,thank you very much :)

Re: back up and restore the modified date

Posted: 05 May 2016 10:31
by highend
I see.

Use this instead:

Code: Select all

"_Initialize"
    global $logFile = "<curpath>\dates.txt";

"Backup file dates..."
    global $logFile;
    $logContent = "";
    foreach($file, <get SelectedItemsPathNames |>) {
        if (exists($file) != 1) { continue; }
        $created  = property("#date.c", $file);
        $modified = property("#date.m", $file);
        $logContent = $logContent . "$file|$created|$modified<crlf>";
    }
    writefile($logFile, $logContent);

"Restore file dates..."
    global $logFile;
    $logContent = readfile($logFile);
    foreach($line, $logContent, <crlf>) {
        $file     = gettoken($line, 1, "|");
        $created  = gettoken($line, 2, "|");
        $modified = gettoken($line, 3, "|");
        if (exists($file) != 1) { continue; }
        timestamp "c", $created, $file;
        timestamp "m", $modified, $file;
    }

Re: back up and restore the modified date

Posted: 05 May 2016 10:57
by xnmp
highend wrote:I see.

Use this instead:
Thank you ,i 've just tested, it works flawlessly
Thank you very much ,highend
you are so Great.