Page 1 of 2

[Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 17 Dec 2014 00:37
by Enternal
TimeSync.xys
TimeSync 1.1 Beta 2 - January 8, 2015
(2.68 KiB) Downloaded 385 times
TimeSync.xys
TimeSync 1.0
(1.62 KiB) Downloaded 328 times
TimeSync 1.0 Beta2
* The script has 2 separate functions now. It can either TimeSync things recursively or not recursively.
* It can now also sync time to "Current Time" or "Oldest Date" (Thanks to Marco!)
* It can now properly time sync folders and subfolders as well.

Just thought to post it here in case someone is interested or too laze to code it. All this does is it allow you to sync the date and time of selected items to any of its other dates. It also allows syncing to current time and manual input as well. For example, you want to sync the time of its created and accessed date to its modified date. You can then simply select the files and folders (it is recursive), select the dates and time that you want to change, and then select what date and time you want it to sync to.

This script is created a while back and related to http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=8068
The version I wrote and used for a while was somewhat broken and crude. Now I fixed it and up and add a few other things for it to do.

Use it by adding the script as a toolbar, catalog item, or UDC. Then you can select the files/folders and then run the script. Simple enough.

Code: Select all

/*
TimeSync 1.0 By Enternal - December 16, 2014
http://www.xyplorer.com/
*/

    Global $Files;
    End ("<selitems>"==""),"Nothing Is Selected!";
    $SelectedItems = Get("SelectedItemsPathNames","|");
    $ToChange = InputSelect("Date(s) to Change:", "Created|Modified|Accessed", "", "10");
    $SyncTo = InputSelect("Sync Date(s) To:", "Created|Modified|Accessed|Current Time|Manual", "", "8");
    If $SyncTo == Manual {$Input = Input("Date & Time Input", "" , FormatDate());}
    ForEach($Item, $SelectedItems, "|") {
        If Exists($Item) == 2 {
            $Files = $Files.FolderReport("files", "r", $Item, "r", , "|")."|"; }
        ElseIf Exists($Item) == 1 {
            $Files = $Files.Report("{Fullname}|", "1")."|"; } }
    $Files = FormatList($Files, "tsed", "|");
    ForEach($Method, $ToChange, "|") {
        $ToChange = Replace($ToChange, "Created", "c");
        $ToChange = Replace($ToChange, "Modified", "m");
        $ToChange = Replace($ToChange, "Accessed", "a");
        $ToChange = Replace($ToChange, "|", "");
        ForEach($Item, $Files, "|") {
            If $SyncTo == "Current Time" {
                $nDate = GetToken(FormatDate(), 1, " ");
                $nTime = GetToken(FormatDate(), 2, " "); }
            ElseIf $SyncTo == Manual {
                $nDate = GetToken($Input, 1, " ");
                $nTime = GetToken($Input, 2, " "); }
            Else {
                $Time = Report("{$SyncTo}", $Item);
                $nDate = GetToken($Time, 1, " ");
                $nTime = GetToken($Time, 2, " "); }
            Timestamp $ToChange, "$nDate $nTime", $Item;
        }
    }

Re: TimeSync 1.0 - December 16, 2014

Posted: 17 Dec 2014 01:18
by Marco
Thanks for sharing.
Another bit of code that might be useful: it syncs the date and time of selected items to the earliest one. Feel free to embed it if you like it.

Code: Select all

 $allitems = get("SelectedItemsPathNames", "|");
 foreach ($item, "$allitems", "|") {
  $m = report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $c = report("{Created yyyy-mm-dd hh:nn:ss.fffffff}", $item);
  $a = report("{Accessed yyyy-mm-dd hh:nn:ss.fffffff}", $item);

  $x = (compare("$m", "$c", "d") == "1")?"$c":"$m";
  $x = (compare("$x", "$a", "d") == "1")?"$a":"$x";

  timestamp, "$x", "$item";
 };

Re: TimeSync 1.0 - December 16, 2014

Posted: 17 Dec 2014 02:00
by Enternal
Lol Marco! That's a good one. I have a few scenarios where I had had to sync to the oldest dates but then I forgot about it. Thanks! I used your code now too. Won't update the main post yet until I can get a few more feedback or bugs.

Code: Select all

/*
TimeSync 1.1B By Enternal - December 16, 2014
Script Home Thread: http://xyplorer.com/xyfc/viewtopic.php?f=7&t=12980
Reference Thread: http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=8068
http://www.xyplorer.com/
Thanks: Marco for "Sync to Oldest Date"
*/

    Global $Files;
    End ("<selitems>"==""),"Nothing Is Selected!";
    $SelectedItems = Get("SelectedItemsPathNames","|");
    $ToChange = InputSelect("Date(s) to Change:", "+Created|Modified|Accessed", "", "10");
    $SyncTo = InputSelect("Sync Date(s) To:", "Created|Modified|Accessed|Current Time|Oldest Time|Manual", "", "8");
    If $SyncTo == Manual {$Input = Input("Date & Time Input", "" , FormatDate());}
    ForEach($Item, $SelectedItems, "|") {
        If Exists($Item) == 2 {
            $Files = $Files.FolderReport("files", "r", $Item, "r", , "|")."|"; }
        ElseIf Exists($Item) == 1 {
            $Files = $Files.Report("{Fullname}|", "1")."|"; } }
    $Files = FormatList($Files, "tsed", "|");
    ForEach($Method, $ToChange, "|") {
        $ToChange = Replace($ToChange, "Created", "c");
        $ToChange = Replace($ToChange, "Modified", "m");
        $ToChange = Replace($ToChange, "Accessed", "a");
        $ToChange = Replace($ToChange, "|", "");
        ForEach($Item, $Files, "|") {
            If $SyncTo == "Current Time" {
                $nDate = GetToken(FormatDate(), 1, " ");
                $nTime = GetToken(FormatDate(), 2, " "); }
            ElseIf $SyncTo == "Manual" {
                $nDate = GetToken($Input, 1, " ");
                $nTime = GetToken($Input, 2, " "); }
            ElseIf $SyncTo == "Oldest Time" {
                $m = Report("{Modified yyyy-mm-dd hh:nn:ss.fffffff}", $Item);
                $c = Report("{Created yyyy-mm-dd hh:nn:ss.fffffff}", $Item);
                $a = Report("{Accessed yyyy-mm-dd hh:nn:ss.fffffff}", $Item);
                $x = (Compare("$m", "$c", "d") == "1")?"$c":"$m";
                $x = (Compare("$x", "$a", "d") == "1")?"$a":"$x";
                $nDate = GetToken($x, 1, " ");
                $nTime = GetToken($x, 2, " ");
                Timestamp, "$x", "$Item"; }
            Else {
                $Time = Report("{$SyncTo}", $Item);
                $nDate = GetToken($Time, 1, " ");
                $nTime = GetToken($Time, 2, " "); }
            Timestamp $ToChange, "$nDate $nTime", $Item;
        }
    }
TimeSync.xys
1.1B
(2.37 KiB) Downloaded 317 times

Re: TimeSync 1.0 - December 16, 2014

Posted: 17 Dec 2014 02:06
by Marco
And if you want to be more hackish, you can rely on this utility to change/set the timestamps: https://github.com/jschicht/SetMace :wink:

Re: TimeSync 1.0 - December 16, 2014

Posted: 17 Dec 2014 21:27
by Enternal
Marco wrote:And if you want to be more hackish, you can rely on this utility to change/set the timestamps: https://github.com/jschicht/SetMace :wink:
Lol! That would make it too complicated now haha. The reason I made it was to give it enough feature but still simple enough. Currently I'm also writing a little tool that mimics RapidCRC Unicode as well and it's not to replace it but to use it whenever I don't have access to RapidCRC or in a rush. On the other hand, SetMace joins my toolbox hehe. Thanks!

Re: [Script] TimeSync 1.0 - December 16, 2014

Posted: 09 Jan 2015 07:11
by Enternal
TimeSync 1.1 Beta 2 is now uploaded!
* The script has 2 separate functions now. It can either TimeSync things recursively or not recursively.
* It can now also sync time to "Current Time" or "Oldest Date" (Thanks to Marco!)
* It can now properly time sync folders and subfolders as well.

Updated 1st post.

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 27 Feb 2015 15:52
by lukescammell
This is pretty cool, thanks!

I've also got a request that is *WAAAAAAAAAAAAY* beyond my skills to hack together:

I semi-often have to end up converting files from one format to another – msg→eml, zip→7z, gif→PNG, cr2→dng – and there are various tools around that achieve this. The problem is that the newly converted files now all have timestamps of "now" and I'd really like to have them take the timestamps (all of them) from the old files they have been converted from.

Would it be possible to modify this script to recursively look through a directory at two different types of file extension and replace the timestamps of the new extension with the timestamps from the old extension?

Example

I'd like to change this:

Code: Select all

    Name      Type   Size        Created           Modified          Accessed
---------------------------------------------------------------------------------
IMG_7921.CR2  CR2  26595574  13/05/2014 09:13  08/05/2014 09:25  13/05/2014 09:58
IMG_7921.dng  DNG  23642414  27/02/2015 14:42  27/02/2015 14:42  27/02/2015 14:42
---------------------------------------------------------------------------------
IMG_7922.CR2  CR2  25585094  13/05/2014 09:13  08/05/2014 09:35  13/05/2014 11:46
IMG_7922.dng  DNG  22545000  27/02/2015 14:42  27/02/2015 14:42  27/02/2015 14:42
---------------------------------------------------------------------------------
IMG_7923.CR2  CR2  25815911  13/05/2014 09:13  17/07/2014 12:23  17/07/2014 12:23
IMG_7923.dng  DNG  22902946  27/02/2015 14:42  27/02/2015 14:42  27/02/2015 14:42
---------------------------------------------------------------------------------
IMG_7924.CR2  CR2  26766586  13/05/2014 09:13  11/05/2014 09:26  13/08/2014 09:48
IMG_7924.dng  DNG  23821478  27/02/2015 14:42  27/02/2015 14:42  27/02/2015 14:42
---------------------------------------------------------------------------------
IMG_7925.CR2  CR2  26690093  13/05/2014 09:13  08/05/2014 09:26  13/05/2014 09:58
IMG_7925.dng  DNG  23732298  27/02/2015 14:42  27/02/2015 14:42  27/02/2015 14:42
To this:

Code: Select all

    Name      Type   Size        Created           Modified          Accessed
---------------------------------------------------------------------------------
IMG_7921.CR2  CR2  26595574  13/05/2014 09:13  08/05/2014 09:25  13/05/2014 09:58
IMG_7921.dng  DNG  23642414  13/05/2014 09:13  08/05/2014 09:25  13/05/2014 09:58
---------------------------------------------------------------------------------
IMG_7922.CR2  CR2  25585094  13/05/2014 09:13  08/05/2014 09:35  13/05/2014 11:46
IMG_7922.dng  DNG  22545000  13/05/2014 09:13  08/05/2014 09:35  13/05/2014 11:46
---------------------------------------------------------------------------------
IMG_7923.CR2  CR2  25815911  13/05/2014 09:13  17/07/2014 12:23  17/07/2014 12:23
IMG_7923.dng  DNG  22902946  13/05/2014 09:13  17/07/2014 12:23  17/07/2014 12:23
---------------------------------------------------------------------------------
IMG_7924.CR2  CR2  26766586  13/05/2014 09:13  11/05/2014 09:26  13/08/2014 09:48
IMG_7924.dng  DNG  23821478  13/05/2014 09:13  11/05/2014 09:26  13/08/2014 09:48
---------------------------------------------------------------------------------
IMG_7925.CR2  CR2  26690093  13/05/2014 09:13  08/05/2014 09:26  13/05/2014 09:58
IMG_7925.dng  DNG  23732298  13/05/2014 09:13  08/05/2014 09:26  13/05/2014 09:58

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 28 Feb 2015 08:32
by bdeshi

Code: Select all

 $src_ext = "CR2"; $trg_ext = "DNG"; $c = 0; $r = "";
 $lst = regexmatches(folderreport(items,r,inputfolder(<curpath>),r,,'|'),"[^|]+\.$src_ext");
 foreach ($src,$lst,'|') {
  $trg = regexreplace($src,'\.'.$src_ext.'$',".$trg_ext");
  if (exists($trg) == 1) {$c++; timestamp ,$src,$trg; $r = $r."<crlf>".$trg;}
 }
 text "$c items' timestamps modified:<crlf>$r",700,700;
Enter timestamp source extension in $src_ext. Enter timestamp target extension in $trg_ext.

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 12:36
by lukescammell
Amazing Sammay – truly outstanding, thank you! :appl:

I've temporarily named this "DateTime Clone One Ext to Another" – catchy I know :D

Apologies to the OP since this really isn't anything to do with the original script now. Incidentally, why doesn't the script work if you don't have space at the very beginning of the second line?

I'll have to see if I can figure out how to improve the script when I get a moment:
  1. Default the folder to the current folder of the active pane
  2. provide two form fields in which to enter the Source ext and Target ext
  3. default those two fields to the extensions of the first two files highlighted
  4. swap field contents button (source becomes target and vice-versa
  5. tickbox option on folder select to only process selected files

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 12:49
by PeterH
lukescammell wrote:Incidentally, why doesn't the script work if you don't have space at the very beginning of the second line?
In short: one script file can contain multiple scripts. Text in column one starts a new script...

(...though, to differentiate the scripts, they usually should be named...)

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 14:00
by bdeshi
lukescammell wrote:
  1. Default the folder to the current folder of the active pane
  2. provide two form fields in which to enter the Source ext and Target ext
  3. default those two fields to the extensions of the first two files highlighted
  4. swap field contents button (source becomes target and vice-versa
  5. tickbox option on folder select to only process selected files
thanks, and:
Here's a revised script that operates on current path and allows 2-in-1 ext input (preset first two selected extensions)
(Actually the script already did default to curpath in the folder select dialog; that selection only remained outside the visible area of the dialog)

Code: Select all

 $ext = input("timestamp source extension|target extension|process selected toggle",
          "eg, cr2|dng|0 or cr2|dng (recursive) OR cr2|dng|1 (selected only)",
          getpathcomponent(gettoken(<get selecteditemspathnames |>,1,'|'),ext).'|'.
            getpathcomponent(gettoken(<get selecteditemspathnames |>,2,'|'),ext));
 $src_ext = gettoken($ext,1,'|'); $trg_ext = gettoken($ext,2,'|');
 if (gettoken($ext,3,'|') == '1') { $lst = regexmatches(<get selecteditemspathnames |>,"[^|]+\.$src_ext"); }
 else { $lst = regexmatches(folderreport(items,r,<curpath>,r,,'|'),"[^|]+\.$src_ext"); }

 $c = 0; $r = "";
 foreach ($src,$lst,'|') {
  $trg = regexreplace($src,'\.'.$src_ext.'$',".$trg_ext");
  if (exists($trg) == 1) {$c++; timestamp ,$src,$trg; $r = $r."<crlf>".$trg;}
 }
 text "$c items' timestamps modified:<crlf>$r",700,700;
Enter source and target extensions separated by pipe |.
A 3rd |-separated token controls processing scope. This is optional and recursive is default. If this is 1, only selected files are processed, if it's missing or anythin other than 1, all files in curpath are processed recursively. CR2|DNG == CR2|DNG|0 == CR2|DNG| != CR2|DNG|1

Note "presetting first two selected extensions" is slightly flawed, it disregards the fact that either or both of first selections can be folders.

[edited]

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 14:55
by lukescammell
Thankyouthankyouthankyou – a million times thank you!

Image

P.S. this works wonderfully and has just saved me about 10GB disk space and hours and hours of mindless slog.

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 15:03
by bdeshi
:D My pleasure!

Now use those liberated hours and become a XYScript whizard! :kidding:

ed. surprised that timestamp change saved disk space! you must've taken some further steps. (Which could've been script-skipped too. :wink: )

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 15:41
by lukescammell
The timestamp didn't save the disk space. The conversion of several hundred .arw and .cr2 files to .dng saved the disk space. I just didn't want to convert the files before (even though DNG is a better archival format – not least it saves disk space!) because I would have lost the original dates. FYI, I used Adobe DNG Converter to transcode the files.

Next up, some ZIP files to convert to 7z…

Re: [Script] TimeSync 1.1 Beta2 - January 8, 2015

Posted: 02 Mar 2015 21:26
by Enternal
Oh, looks like the problem is solved! :)

Actually, perhaps you could try using XnConvert in the future. It has an option that allows you to retain the original file's date and time.
http://www.xnview.com/en/xnconvert/

I checked that it also supports both of your file types. Well, it does support over 500 image types so...
http://www.xnview.com/en/xnconvert/#formats

Btw, thanks SammarySarkar! That script just saved me time from writing a portion of a new option!