Sync Timestamps for Several Files Based Off BASENAME.

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Sync Timestamps for Several Files Based Off BASENAME.

Post by SkyFrontier »

This is part of a project in which I was sync'ing timestamps in order to update some .txt/.htm pairs of files thus preserving displaying modes intact. Really useful, if you are a researcher. 8)
ToDo: it requires some error-handling - working on it. Any help is appreciated.

Code: Select all

//Sync Timestamps for Several Files Based Off BASENAME
   msg "Is TARGET located on active pane and BASE/source of timestamps on the opposite pane?<crlf>Did you selected only ONE file which has a clone on the inactive pane as base for names?<crlf>-otherwise script WILL fail!<crlf><crlf>If you has YES for both questions, please click OK to continue.", 1, ;
   $a = "<curbase>";
   $b = "<curname>";
   focus("pi");

   $check = exists("$b");
   if ($check == 1) { }
   elseif {
   end ($check = 0), "File does not exists on the opposite file!";
   }

   selfilter $b;

   $dateFormat = 'yyyy-mm-dd hh:nn:ss';
   $rC = report("{Created $dateFormat}",1);
   $rM = report("{Modified $dateFormat}",1);
   $rA = report("{Accessed $dateFormat}",1);

   focus("pi");

   selfilter $a;
   timestamp m, "$rM";
   timestamp c, "$rC";
   timestamp a, "$rA";
   status "Job done! Who's next?!";
Error handling, phase 1:

Code: Select all

   end (<xyver> < "9.70.0009"), "Sorry - this script requires XYplorer version 9.70.0009 or higher.<crlf>Click 'Ok' to exit.";
   $b = "<curname>";
   focus("pi");
   focus;
   $c = listpane(, "$b", 1 + 8);
   if (Exists("$c")==1)  { echo "hi!"; };
   else (Exists("$c")==0) { echo "Sorry - try again"; };
-but it must allow script to work on <curbase> instead of just <curname>.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Sync Timestamps for Several Files Based Off BASENAME.

Post by SkyFrontier »

Final version:
-error checking galore - it's nearly impossible for it to fail (and as some of you will notice, this is the kind of operation which doesn't allow a single error!); please report any bug if you find one.

Code: Select all

//Sync Timestamps for Several Files Based Off BASENAME
   msg "Is TARGET located on active pane and BASE/source of<crlf>timestamps on the opposite pane?<crlf><crlf>Did you selected only ONE file which has a same basename<crlf>counterpart on the inactive pane as base for timestamping?<crlf>-otherwise script WILL fail!<crlf><crlf>If you has YES for both questions, please click OK to continue.", 1, ;
   $count1 = <get countselected>;
   if (0 == $count1)
   {
      end 1, 'There must be at least one item selected as source.', 1;
   }
   elseif ($count1 > 1)
   {
      end 1, 'There must be no more than one item selected as source.', 1;
   }

   $a = "<curname>";
   focus("pi");
   $pi = "<get pane>";
   selfilter """$a""";

   $items = getinfo("CountSelected");
   END ($items == 0), "Sorry - no suitable files available on pane $pi!<crlf>Script will shut now.";
//   if($items >= 2) { selfilter """$b""" }

   $dateFormat = 'yyyy-mm-dd hh:nn:ss';
   $rC = report("{Created $dateFormat}",1);
   $rM = report("{Modified $dateFormat}",1);
   $rA = report("{Accessed $dateFormat}",1);
   selpos '+1';

   focus("pi");

   selfilter """$a""";
   timestamp m, "$rM";
   timestamp c, "$rC";
   timestamp a, "$rA";
   selpos '+1';
//enable/disable the next two lines if you want/not the "run script again" function
//   setting "AllowRecursion", 1;
//   #755;
   status "Job done! Who's next?!";
ToDo: perhaps some pane-jumping can be avoided... will check later.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply