Touch : Set Created/Modified Dates of Selected Items

Discuss and share scripts and script files...
Post Reply
jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Touch : Set Created/Modified Dates of Selected Items

Post by jacky »

Since there's been talked about touching/time-stamping items lately, I thought I'd share this little script of mine.

It can be used to set either Created or Modified dates of selected items. You'll be asked for a date or pattern to be set. It can be:
- A date/time, obviously (empty for Now)
- ! to just reset the time (to 00:00:00)
- c or m to set to the created or modified date, with suffix ! to reset time as well
- an very basic "operation", e.g. +4 or -2 to add/subtract days to the current date
- those "operations" can have c or m added to refer to another date, e.g. +2m means the Modified date + 2 days
- you can finally also add ! to reset time, e.g. -1c! means Created date minus one day, and time reset

There's option to either :
- get asked the new pattern/date for each item individually
- get asked once, "calculate" the date (based on date of current/first item) and apply it to all items (same as done in XY)
- get asked once, and "calculate" the date for each item (pattern applied to each item with its own date, not possible in XY other than manually doing it)

The core of it allows to be asked for the new date/pattern, or you can set it in a global variable and thus create automatic command with predefined dates. A couple of examples are included so you can see how it works.

Code: Select all

"Set Modified to Now : Touch"
	timestamp m, "";
"Set Created to Modified (no time) : TouchCreatedToModified"
	global $type_gbl, $group_gbl, $new_date_gbl;
	$type_gbl = "c"; // Created
	$group_gbl = 2; // Pattern for all items
	$new_date_gbl = "m!"; // Modified, Time reset
	sub _touchStart;
-
"Set Modified to Tomorrow (no time) : TouchModifiedTomorrow"
	global $day_number_gbl, $date_gbl;
	// Today
	$date_gbl = <date dd/mm/yyyy>;
	load Dates, _getNumberFromDate;
	// Tomorrow
	$day_number_gbl = $day_number_gbl + 1;
	load Dates, _getDateFromNumber;
	// direct touch
	timestamp m, $date_gbl;
	// done
	status "Timestamping complete";
"Set Modified to Next Day of Current (no time) : TouchModifiedNextDay"
	global $type_gbl, $group_gbl, $new_date_gbl;
	$type_gbl = "m"; // Modified
	$group_gbl = 1; // Value for all items
	$new_date_gbl = "+1m!"; // Modified + 1 day
	sub _touchStart;
-
"Change Created Date... (Pattern) : TouchCreatedPattern"
	global $type_gbl, $group_gbl;
	$type_gbl = "c";
	$group_gbl = 2;
	sub _touchStart;
"Change Modified Date... (Pattern) : TouchModifiedPattern"
	global $type_gbl, $group_gbl;
	$type_gbl = "m";
	$group_gbl = 2;
	sub _touchStart;
"- : _sep"
"Change Created Date... (Value) : _TouchCreatedValue"
	global $type_gbl, $group_gbl;
	$type_gbl = "c";
	$group_gbl = 1;
	sub _touchStart;
"Change Modified Date... (Value) : _TouchModifiedValue"
	global $type_gbl, $group_gbl;
	$type_gbl = "m";
	$group_gbl = 1;
	sub _touchStart;
"- : _sep"
"Change Created Date... (Options) : _TouchCreatedOpts"
	global $type_gbl;
	$type_gbl = "c";
	sub _touchStart;
"Change Modified Date... (Options) : _TouchModifiedOpts"
	global $type_gbl;
	$type_gbl = "m";
	sub _touchStart;
-
"Show Full Menu..."
	load *,*;
"Cancel"



"_touchStart"
	global $list_gbl, $group_gbl;
	// set options if not done already
	sub ( $group_gbl == "" ) ? "_touchOptions" : "_nothing";
	// creates the list to work with : Full path/name and the dates of references, already formatted
	$list_gbl = report("{Fullname}{Created dd/mm/yyyyhh:nn:ss}{Modified dd/mm/yyyyhh:nn:ss}|", 1);
	// if current item in selection, move it first so it's the reference one when applied to all selected items at once
	sub (<curitem> == "") ? "_nothing" : "_touchCurItemFirst";
	// go go go
	sub _touchLoop;
	// done
	status "Timestamping complete";
"_touchOptions"
	global $group_gbl;
	// set options : 0 = ask pattern/date for all items; 1= calculate date for first item, apply to all items; 2= apply pattern to all items (calculated for each one)
	$group_gbl = (getinfo("CountSelected") > 1) ? confirm("Do you want to touch all selected items at once ?<br><br>OK = All items at once<br>Cancel = All items individually") : 0;
	$group_gbl = ($group_gbl == 1) ? 1 + confirm("Do you want the pattern to be applied to all selected items ?<br><br>OK = Pattern, e.g. m = modified date of each item<br>Cancel = First resolved value, e.g. m = modified date of first item") : 0;
"_touchCurItemFirst"
	global $list_gbl;
	// length of path/name
	strlen $l, <curitem>;
	// finds the item
	strpos $p, $list_gbl, <curitem>;
	// items before
	substr $bef, $list_gbl, 0, $p;
	// current item (w/ dates)  37 = dates (36) + pipe
	substr $itm, $list_gbl, $p, $l + 37;
	// items before
	substr $aft, $list_gbl, $p + $l + 37;
	// move current to top of list
	$list_gbl = $itm.$bef.$aft
"_touchLoop"
	global $list_gbl, $item_gbl;
	// get end of item's data
	strpos $p, $list_gbl, "|";
	// extract item
	substr $item_gbl, $list_gbl, 0, $p;
	// remove it from list
	substr $list_gbl, $list_gbl, $p + 1;
	// do the work
	sub _touch;
	// continue?
	sub ($list_gbl == "") ? "_nothing" : "_touchLoop";
"_touch"
	global $type_gbl, $new_date_gbl, $item_gbl, $dates_gbl, $group_gbl;
	// ensure an item do timestamp
	assert ($item_gbl != ""), "No item selected !";
	// get created/modified dates
	substr $c_date, $item_gbl, -36, -26;
	substr $c_time, $item_gbl, -26, -18;
	substr $m_date, $item_gbl, -18, -8;
	substr $m_time, $item_gbl, -8;
	// for later use in loaded scripts, because I don't want to global them all...
	$dates_gbl = '$c_date = "'.$c_date.'"; $c_time = "'.$c_time.'"; $m_date = "'.$m_date.'"; $m_time = "'.$m_time.'";';
	// get item's path/name & name only
	substr $item, $item_gbl, 0, -36;
	regexreplace $name, $item, "^.+\\([^\\]+)$", "$1";
	
	// ask for new date if needed
	load ( ($new_date_gbl == "") ? ('global $type_gbl, $new_date_gbl, $group_gbl; '.$dates_gbl.' input $new_date_gbl, (($type_gbl == "m") ? "Modified" : "Created") . " ".(($group_gbl == 2) ? "pattern" : "date")." for ".(($group_gbl >= 1) ? (getinfo("CountSelected") . " selected items") : """'.$name.'""")."  |  [empty] = Now; ! = Reset time; +/-[0-9][cm]! = Maths", "$'.$type_gbl.'_date $'.$type_gbl.'_time";') : 'call'),,s;
	// trick so that an empty pattern canbe applied in batch without cause a prompt
	$new_date_gbl = ($new_date_gbl == "Now") ? "" : $new_date_gbl;
	
	// save pattern (might need to restore it once done with this item)
	$pattern = $new_date_gbl;
	
	// deal with operations ( +/- [0-9] [cm] ! )
	substr $sign, $new_date_gbl, 0, 1;
	sub ( ($sign == "+") + ($sign == "-") == 1 ) ? "_touchOp" : "_nothing";
	
	// set to modified/created date (with !-suffix to reset time)
	load ( ( ($sign == "m") + ($sign == "c") == 1 ) ? ('global $new_date_gbl; '.$dates_gbl.' substr $new_date_gbl, $new_date_gbl, 1; $new_date_gbl = "$'.$sign.'_date ".(($new_date_gbl == "!") ? "00:00:00" : "$'.$sign.'_time");') : 'call'),,s;
	
	// reset hour
	load ( ($new_date_gbl == "!") ? ('global $new_date_gbl; '.$dates_gbl.' $new_date_gbl = "$'.$type_gbl.'_date 00:00:00";') : 'call'),,s;
	
	// touching -- if group == 1 then touch all items and be done with it already, otherwise it's this one item and moving on to the next...
	self $file, file;
	load ( ( $group_gbl == 1) ? ('global $tmp_gbl; $tmp_gbl = "'.$item.'"; load "'.$file.'", "_touchAll";') : "timestamp $type_gbl, ""$new_date_gbl"", ""$item"";" ),,s;
	
	// restore for when looping -- w/ trick so that an empty pattern canbe applied in batch without cause a prompt
	$new_date_gbl = ($group_gbl == 0) ? "" : (($group_gbl == 1) ? (($new_date_gbl == "") ? "Now" : $new_date_gbl) : (($pattern == "") ? "Now" : $pattern));
"_touchOp"
	global $type_gbl, $new_date_gbl, $item_gbl, $date_gbl, $day_number_gbl, $tmp_gbl;
	// get created/modified dates
	substr $c_date, $item_gbl, -36, -26;
	substr $c_time, $item_gbl, -26, -18;
	substr $m_date, $item_gbl, -18, -8;
	substr $m_time, $item_gbl, -8;
	// sign
	substr $sign, $new_date_gbl, 0, 1;
	// remove sign from value
	substr $tmp_gbl, $new_date_gbl, 1;
	// get flag ( ! == reset time )
	substr $flag, $tmp_gbl, -1;
	// if flag found, remove it from value
	load (($flag == "!") ? 'global $tmp_gbl; substr $tmp_gbl, $tmp_gbl, 0, -1;' : 'call'),,s;
	// get last char, might be type (c/m)
	substr $type, $tmp_gbl, -1;
	// if type not specified, we add it
	load ( ( ($type == "m") + ($type == "c") == 0 ) ? 'global $tmp_gbl, $type_gbl; $tmp_gbl = $tmp_gbl.$type_gbl;' : 'call'),,s;
	// now get value (all minus type)
	substr $value, $tmp_gbl, 0, -1;
	// and get type
	substr $type, $tmp_gbl, -1;
	
	// get reference date
	$date_gbl = eval('$'.$type.'_date');
	// calc its day number
	load Dates, _getNumberFromDate;
	// do the maths
	$day_number_gbl = eval("$day_number_gbl $sign $value");
	// get the new date back
	load Dates, _getDateFromNumber;
	// return it, with time unless flagged to reset
	$new_date_gbl = "$date_gbl " . (($flag == "!") ? "00:00:00" : eval('$'.$type.'_time'));
"_touchAll"
	global $type_gbl, $new_date_gbl, $tmp_gbl, $list_gbl;
	// removes dates from list
	regexreplace $list_gbl, $list_gbl, "(.+?).{36}(\|)", "$1$2";
	// remove last pipe
	substr $list_gbl, $list_gbl, 0, -1;
	// add the extracted item
	$list_gbl = ($list_gbl == "") ? $tmp_gbl : "$tmp_gbl|$list_gbl";
	// touch
	timestamp $type_gbl, $new_date_gbl, $list_gbl;
	// and done!
	$list_gbl = "";
"_nothing"
EDIT: :oops: Forgot that little dependency, this shall be Dates.xys put in the same folder as the script file above :

Code: Select all

// Dates Operations -- based on http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html

"_floor"
	global $floor_gbl, $floor_rnd_gbl;
	strpos $p, $floor_gbl, ".";
	$p = ($p == -1) ? "" : $p;
	substr $r, $floor_gbl, $p;
	substr $floor_gbl, $floor_gbl, 0, $p;
	$s = 'global $floor_gbl; $floor_gbl = $floor_gbl + '.($r >= 0.5);
	load (($floor_rnd_gbl == 1) ? $s : 'call'),,s;
	$s = 'global $floor_gbl; $floor_gbl = '.($floor_gbl-1);
	load (($floor_gbl < 0) ? $s : 'call'),,s;
	$floor_rnd_gbl = 0;

"_mod"
	global $mod1_gbl, $mod2_gbl, $floor_gbl;
	$floor_gbl = $mod1_gbl / $mod2_gbl;
	sub _floor;
	$mod1_gbl = $mod1_gbl - $mod2_gbl * $floor_gbl;

"_getNumberFromDate"
	global $date_gbl, $day_number_gbl;
	global $mod1_gbl, $mod2_gbl, $floor_gbl;
	
	substr $day, $date_gbl, 0, 2;
	substr $month, $date_gbl, 3, 2;
	substr $year, $date_gbl, -4;
	
	$mod1_gbl = $month + 9;
	$mod2_gbl = 12;
	sub _mod;
	$month = $mod1_gbl;
 	
 	$floor_gbl = $month/10;
 	sub _floor;
 	$year = $year - $floor_gbl;
 	
 	$day_number_gbl = 365*$year;
 	
 	$floor_gbl = $year/4;
 	sub _floor;
 	$day_number_gbl = $day_number_gbl + $floor_gbl;

 	$floor_gbl = $year/100;
 	sub _floor;
 	$day_number_gbl = $day_number_gbl - $floor_gbl;

 	$floor_gbl = $year/400;
 	sub _floor;
 	$day_number_gbl = $day_number_gbl + $floor_gbl;

 	$floor_gbl = ($month*306 + 5)/10;
 	sub _floor;
 	$day_number_gbl = $day_number_gbl + $floor_gbl;
 	
 	$day_number_gbl = $day_number_gbl + $day - 1;

"_getDateFromNumber"
	global $date_gbl, $year_gbl, $day_number_gbl;
	global $mod1_gbl, $mod2_gbl, $floor_gbl;
	
	$day_number_gbl = $day_number_gbl;
	$year = 10000 * $day_number_gbl + 14780;
	$floor_gbl = $year / 3652425;
	sub _floor;
	$year = $floor_gbl;
	
 	$ddd = 365 * $year;
 	
 	$floor_gbl = $year/4;
 	sub _floor;
 	$ddd = $ddd + $floor_gbl;
	
 	$floor_gbl = $year/100;
 	sub _floor;
 	$ddd = $ddd - $floor_gbl;
	
 	$floor_gbl = $year/400;
 	sub _floor;
 	$ddd = $ddd + $floor_gbl;
 	
 	$ddd = $day_number_gbl - $ddd;
 	
 	$year_gbl = $year;
 	$floor_gbl = $ddd;
 	sub ($ddd < 0) ? "_dfnAdjust" : "_nothing";
 	$ddd = $floor_gbl;
 	
 	$floor_gbl = (100 * $ddd + 52) / 3060;
 	sub _floor;
 	$mi = $floor_gbl;
 	
 	$mod1_gbl = $mi + 2;
 	$mod2_gbl = 12;
 	sub _mod;
 	$month = $mod1_gbl + 1;
 	
 	$floor_gbl = ($mi + 2) / 12;
 	sub _floor;
 	$year = $year_gbl + $floor_gbl;
 	
 	$floor_gbl = ($mi * 306 + 5) / 10;
 	sub _floor;
 	$day = ($ddd - $floor_gbl) + 1;
 	
 	substr $day, "0$day", -2;
 	substr $month, "0$month", -2;
 	$date_gbl = "$day-$month-$year";
 	
"_dfnAdjust"
	global $year_gbl, $day_number_gbl;
	global $floor_gbl;
	
	$year_gbl = $year_gbl - 1;
	
 	$ddd = 365 * $year;
 	
 	$floor_gbl = $year/4;
 	sub _floor;
 	$ddd = $ddd + $floor_gbl;
	
 	$floor_gbl = $year/100;
 	sub _floor;
 	$ddd = $ddd - $floor_gbl;
	
 	$floor_gbl = $year/400;
 	sub _floor;
 	$ddd = $ddd + $floor_gbl;
	
	$ddd = $day_number_gbl - $ddd;
	
	$floor_gbl = $ddd;

"_nothing"
Last edited by jacky on 21 Nov 2008 01:43, edited 2 times in total.
Proud XYplorer Fanatic

graham
Posts: 457
Joined: 24 Aug 2007 22:08
Location: Isle of Man

Re: Touch : Set Created/Modified Dates of Selected Items

Post by graham »

Jacky wrote:
I thought I'd share this little script of mine.
So, when is the big one coming!

This is really making XY a Swiss Knife. Well done!

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by j_c_hallgren »

graham wrote:
jacky wrote:I thought I'd share this little script of mine.
So, when is the big one coming!

This is really making XY a Swiss Knife. Well done!
At this rate, jacky will have a script to make XY dual-pane before Don gets it coded! :lol:

jacky's expertise in scripting has left me SO far behind in the dust that I won't even try to follow so guess I'll just concentrate on trying to help newbies and making little improvements here & there. :wink: Oh, and trying to help make sure that the English used here/website doesn't get too far off-track..
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by admin »

j_c_hallgren wrote:
graham wrote:
jacky wrote:I thought I'd share this little script of mine.
So, when is the big one coming!

This is really making XY a Swiss Knife. Well done!
At this rate, jacky will have a script to make XY dual-pane before Don gets it coded! :lol:
:lol: Oh yes, please jacky!

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by admin »

jacky, looks like there's a dependency: "Dates.xys" ... or is this a test and we shall write Dates.xys at home? :wink:

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by jacky »

Thanks guys, glad you like it :) I think I'll leave DP to Don though... we need to leave him something to do :P ;)
admin wrote:jacky, looks like there's a dependency: "Dates.xys" ... or is this a test and we shall write Dates.xys at home? :wink:
:oops: Right, was a bit tired and I completely forgot to include that one, sorry. Edited the first post, so if you couldn't write it at home you can now just copy/paste ;)
Proud XYplorer Fanatic

RalphM
Posts: 1932
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Touch : Set Created/Modified Dates of Selected Items

Post by RalphM »

Hi Jacky

Thanks for yet another great "little" script of yours, he he (for the little)

Just saw a small typo "Timestapping complete" instead of "Timestamping complete" with two occurences in the first script file...
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by jacky »

RalphM wrote:Just saw a small typo "Timestapping complete" instead of "Timestamping complete" with two occurences in the first script file...
oh right, fixed. Thanks :)
Proud XYplorer Fanatic

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

Re: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

Trying to fix this:
Section/function "Set Modified to Next Day of Current (no time) : TouchModifiedNextDay" is not working.

Problem seems to be here:

Code: Select all

   self $file, file;
   load ( ( $group_gbl == 1) ? ('global $tmp_gbl; $tmp_gbl = "'.$item.'"; load "'.$file.'", "_touchAll";') : "timestamp $type_gbl, ""$new_date_gbl"", ""$item"";" ),,s;
specifically with the self $file, file; and load "'.$file.'" sections.
-any help on this, please...?
Thanks!

EDIT: Added the "Append Yesterday's Date (rel. MOD. attrib.) to Name" function; fixed recursion problems.

(work in progress...)

Code: Select all

"Set Modified to Now : Touch"
   timestamp m, "";
"Set Created to Modified (no time) : TouchCreatedToModified"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl, $new_date_gbl;
   $type_gbl = "c"; // Created
   $group_gbl = 2; // Pattern for all items
   $new_date_gbl = "m!"; // Modified, Time reset
   sub _touchStart;
-
"Set Modified to Tomorrow (no time) : TouchModifiedTomorrow"
   Setting "AllowRecursion", 1;
   global $day_number_gbl, $date_gbl;
   // Today
   $date_gbl = <date dd/mm/yyyy>;
   load Dates, _getNumberFromDate;
   // Tomorrow
   $day_number_gbl = $day_number_gbl + 1;
   load Dates, _getDateFromNumber;
   // direct touch
   timestamp m, $date_gbl;
   // done
   status "Timestamping complete";
"Set Modified to Next Day of Current (no time) : TouchModifiedNextDay"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl, $new_date_gbl;
   $type_gbl = "m"; // Modified
   $group_gbl = 1; // Value for all items
   $new_date_gbl = "+1m!"; // Modified + 1 day
   sub _touchStart;
"Append Yesterday's Date (rel. MOD. attrib.) to Name"
   Setting "AllowRecursion", 1;
   $day = <datem dd>;
   sub ($day == 1) ? '_doMonth' : '_nothing';
   end $day == 1,,1;
   substr $day, "0" . ($day - 1), -2;
   rename b, "* <datem mm>-$day-<datem yyyy>";
"_doMonth"
   Setting "AllowRecursion", 1;
   global $CJ_date, $CJ_day_number;
   $CJ_date = <datem dd/mm/yyyy>;
   $CJ_day_number = $CJ_day_number - 1;
   substr $day, $CJ_date, 0, 2;
   substr $month, $CJ_date, 3, 2;
   substr $year, $CJ_date, -4;
   rename b, "* $month-$day-$year";
"_nothing"
-
"Change Created Date... (Pattern) : TouchCreatedPattern"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl;
   $type_gbl = "c";
   $group_gbl = 2;
   sub _touchStart;
"Change Modified Date... (Pattern) : TouchModifiedPattern"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl;
   $type_gbl = "m";
   $group_gbl = 2;
   sub _touchStart;
"- : _sep"
"Change Created Date... (Value) : _TouchCreatedValue"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl;
   $type_gbl = "c";
   $group_gbl = 1;
   sub _touchStart;
"Change Modified Date... (Value) : _TouchModifiedValue"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl;
   $type_gbl = "m";
   $group_gbl = 1;
   sub _touchStart;
"- : _sep"
"Change Created Date... (Options) : _TouchCreatedOpts"
   Setting "AllowRecursion", 1;
   global $type_gbl;
   $type_gbl = "c";
   sub _touchStart;
"Change Modified Date... (Options) : _TouchModifiedOpts"
   Setting "AllowRecursion", 1;
   global $type_gbl;
   $type_gbl = "m";
   sub _touchStart;
-
"Show Full Menu..."
   load *,*;
"Cancel"



"_touchStart"
   Setting "AllowRecursion", 1;
   global $list_gbl, $group_gbl;
   // set options if not done already
   sub ( $group_gbl == "" ) ? "_touchOptions" : "_nothing";
   // creates the list to work with : Full path/name and the dates of references, already formatted
   $list_gbl = report("{Fullname}{Created dd/mm/yyyyhh:nn:ss}{Modified dd/mm/yyyyhh:nn:ss}|", 1);
   // if current item in selection, move it first so it's the reference one when applied to all selected items at once
   sub (<curitem> == "") ? "_nothing" : "_touchCurItemFirst";
   // go go go
   sub _touchLoop;
   // done
   status "Timestamping complete";
"_touchOptions"
   Setting "AllowRecursion", 1;
   global $group_gbl;
   // set options : 0 = ask pattern/date for all items; 1= calculate date for first item, apply to all items; 2= apply pattern to all items (calculated for each one)
   $group_gbl = (getinfo("CountSelected") > 1) ? confirm("Do you want to touch all selected items at once ?<br><br>OK = All items at once<br>Cancel = All items individually") : 0;
   $group_gbl = ($group_gbl == 1) ? 1 + confirm("Do you want the pattern to be applied to all selected items ?<br><br>OK = Pattern, e.g. m = modified date of each item<br>Cancel = First resolved value, e.g. m = modified date of first item") : 0;
"_touchCurItemFirst"
   Setting "AllowRecursion", 1;
   global $list_gbl;
   // length of path/name
   strlen $l, <curitem>;
   // finds the item
   strpos $p, $list_gbl, <curitem>;
   // items before
   substr $bef, $list_gbl, 0, $p;
   // current item (w/ dates)  37 = dates (36) + pipe
   substr $itm, $list_gbl, $p, $l + 37;
   // items before
   substr $aft, $list_gbl, $p + $l + 37;
   // move current to top of list
   $list_gbl = $itm.$bef.$aft
"_touchLoop"
   Setting "AllowRecursion", 1;
   global $list_gbl, $item_gbl;
   // get end of item's data
   strpos $p, $list_gbl, "|";
   // extract item
   substr $item_gbl, $list_gbl, 0, $p;
   // remove it from list
   substr $list_gbl, $list_gbl, $p + 1;
   // do the work
   sub _touch;
   // continue?
   sub ($list_gbl == "") ? "_nothing" : "_touchLoop";
"_touch"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $item_gbl, $dates_gbl, $group_gbl;
   // ensure an item do timestamp
   assert ($item_gbl != ""), "No item selected !";
   // get created/modified dates
   substr $c_date, $item_gbl, -36, -26;
   substr $c_time, $item_gbl, -26, -18;
   substr $m_date, $item_gbl, -18, -8;
   substr $m_time, $item_gbl, -8;
   // for later use in loaded scripts, because I don't want to global them all...
   $dates_gbl = '$c_date = "'.$c_date.'"; $c_time = "'.$c_time.'"; $m_date = "'.$m_date.'"; $m_time = "'.$m_time.'";';
   // get item's path/name & name only
   substr $item, $item_gbl, 0, -36;
   regexreplace $name, $item, "^.+\\([^\\]+)$", "$1";
   
   // ask for new date if needed
   load ( ($new_date_gbl == "") ? ('global $type_gbl, $new_date_gbl, $group_gbl; '.$dates_gbl.' input $new_date_gbl, (($type_gbl == "m") ? "Modified" : "Created") . " ".(($group_gbl == 2) ? "pattern" : "date")." for ".(($group_gbl >= 1) ? (getinfo("CountSelected") . " selected items") : """'.$name.'""")."  |  [empty] = Now; ! = Reset time; +/-[0-9][cm]! = Maths", "$'.$type_gbl.'_date $'.$type_gbl.'_time";') : 'call'),,s;
   // trick so that an empty pattern canbe applied in batch without cause a prompt
   $new_date_gbl = ($new_date_gbl == "Now") ? "" : $new_date_gbl;
   
   // save pattern (might need to restore it once done with this item)
   $pattern = $new_date_gbl;
   
   // deal with operations ( +/- [0-9] [cm] ! )
   substr $sign, $new_date_gbl, 0, 1;
   sub ( ($sign == "+") + ($sign == "-") == 1 ) ? "_touchOp" : "_nothing";
   
   // set to modified/created date (with !-suffix to reset time)
   load ( ( ($sign == "m") + ($sign == "c") == 1 ) ? ('global $new_date_gbl; '.$dates_gbl.' substr $new_date_gbl, $new_date_gbl, 1; $new_date_gbl = "$'.$sign.'_date ".(($new_date_gbl == "!") ? "00:00:00" : "$'.$sign.'_time");') : 'call'),,s;
   
   // reset hour
   load ( ($new_date_gbl == "!") ? ('global $new_date_gbl; '.$dates_gbl.' $new_date_gbl = "$'.$type_gbl.'_date 00:00:00";') : 'call'),,s;
   
   // touching -- if group == 1 then touch all items and be done with it already, otherwise it's this one item and moving on to the next...
   self $file, file;
   load ( ( $group_gbl == 1) ? ('global $tmp_gbl; $tmp_gbl = "'.$item.'"; load "'.$file.'", "_touchAll";') : "timestamp $type_gbl, ""$new_date_gbl"", ""$item"";" ),,s;
   
   // restore for when looping -- w/ trick so that an empty pattern canbe applied in batch without cause a prompt
   $new_date_gbl = ($group_gbl == 0) ? "" : (($group_gbl == 1) ? (($new_date_gbl == "") ? "Now" : $new_date_gbl) : (($pattern == "") ? "Now" : $pattern));
"_touchOp"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $item_gbl, $date_gbl, $day_number_gbl, $tmp_gbl;
   // get created/modified dates
   substr $c_date, $item_gbl, -36, -26;
   substr $c_time, $item_gbl, -26, -18;
   substr $m_date, $item_gbl, -18, -8;
   substr $m_time, $item_gbl, -8;
   // sign
   substr $sign, $new_date_gbl, 0, 1;
   // remove sign from value
   substr $tmp_gbl, $new_date_gbl, 1;
   // get flag ( ! == reset time )
   substr $flag, $tmp_gbl, -1;
   // if flag found, remove it from value
   load (($flag == "!") ? 'global $tmp_gbl; substr $tmp_gbl, $tmp_gbl, 0, -1;' : 'call'),,s;
   // get last char, might be type (c/m)
   substr $type, $tmp_gbl, -1;
   // if type not specified, we add it
   load ( ( ($type == "m") + ($type == "c") == 0 ) ? 'global $tmp_gbl, $type_gbl; $tmp_gbl = $tmp_gbl.$type_gbl;' : 'call'),,s;
   // now get value (all minus type)
   substr $value, $tmp_gbl, 0, -1;
   // and get type
   substr $type, $tmp_gbl, -1;
   
   // get reference date
   $date_gbl = eval('$'.$type.'_date');
   // calc its day number
   load Dates, _getNumberFromDate;
   // do the maths
   $day_number_gbl = eval("$day_number_gbl $sign $value");
   // get the new date back
   load Dates, _getDateFromNumber;
   // return it, with time unless flagged to reset
   $new_date_gbl = "$date_gbl " . (($flag == "!") ? "00:00:00" : eval('$'.$type.'_time'));
"_touchAll"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $tmp_gbl, $list_gbl;
   // removes dates from list
   regexreplace $list_gbl, $list_gbl, "(.+?).{36}(\|)", "$1$2";
   // remove last pipe
   substr $list_gbl, $list_gbl, 0, -1;
   // add the extracted item
   $list_gbl = ($list_gbl == "") ? $tmp_gbl : "$tmp_gbl|$list_gbl";
   // touch
   timestamp $type_gbl, $new_date_gbl, $list_gbl;
   // and done!
   $list_gbl = "";
"_nothing"
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...

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Touch : Set Created/Modified Dates of Selected Items

Post by admin »

This might inspire you even further:

Code: Select all

          //set modified date of current file to its EXIF + 6 hours
          ::timestamp m, formatdate("<dateexif>", , "h", 6);

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

Re: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

Came up with those:

Code: Select all

"&Timezoned TimeStamping from EXIF|:rename"
   input $tz, "Set TZ(in min; neg. v. allowed)(table: 1>60;2>120;3>180;3:30>210;4>240;4:30>270;5>300;5:30>330;5:45>345;6>360;6:30>390;7>420;8>480;8:45>525;9>540;9:30>570;10>600;10:30>630;11>660;11:30>690;12>720;12:45>765;13>780;14>840)", "-480";
   input $at, "Attribs/set: a(cc.)/m(od.)/c(r.); blank for ALL; dual in any order/combination", "m";
   timestamp $at, formatdate("<dateexif>", , "n", $tz);
-but having problems to display suggested values! Any ideas, people?
EDIT: flexibility in adding attribs to be set; reduced wording.
---
Will think on a better/interesting UI/functionality for this one... :wink:

Code: Select all

::text formatdate(report ("{created}",1), "Zodiac");
-was wondering if xyHTM(L) could support displaying external images, what about...?
-synastry support? :mrgreen:

To do: some sort of error handling/items counting (min/max=1?)...

Thank you for the idea, Don!
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: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

Can someone please help me finish this?
"Run Script" is not making this timestamp $attrib, formatdate("<dateexif>", , "n", $tzone); to work. Steeping is not giving any clues.
Thanks!

Code: Select all

"Timezoned TimeStamping from EXIF"

   $tzone = "-480";
   $attrib = "mc";

   $TimezonedEXIF = utf8decode(html('<HTML>
   <BODY bgcolor="antiquewhite">
   <FORM method="GET" action="confirm:">
   <TABLE width="99%" border="1" bgcolor="olive">
   <strong>Enter Desired Timezone</strong> (in minutes)<br>
   Conversion Table (Suggested Values)<br>
   1h > 60min; 2h > 120min;3h > 180min; 3:30h > 210min; 4h > 240min; 4h30 > 270min; 5h > 300min; 5h30 > 330min; 5h45 > 345min; 6h > 360min; 6h30 > 390min; 7h > 420min; 8h > 480min; 8h45 > 525min; 9h > 540min; 9h30 > 570min; 10h > 600min; 10h30 > 630min; 11h > 660min; 11h30 > 690min; 12h > 720min; 12h45 > 765min; 13h > 780min; 14h > 840.<br>
   Negative values are allowed (e.g. <strong>-480 min</strong> stands for <strong>UTC - 8</strong>, Pacific Standard Time):<br>
   <TEXTAREA name="tzone" rows=1 cols=12>' . $tzone . '</TEXTAREA><BR>
   <strong>Attributes to be Set</strong> (<strong>a</strong>ccessed/<strong>m</strong>odified/<strong>c</strong>reated)<br>
   Leave blank for ALL; dual in any order/combination (e.g: <strong>mc</strong>; <strong>ma</strong>; <strong>ac</strong>):<br>
   <TEXTAREA name="attrib" rows=1 cols=12>' . $attrib . '</TEXTAREA><BR>
   <INPUT TYPE=SUBMIT STYLE=background:92C7C7 title="All set? Press and get the job done!" name="submit" value="Run Script">

    </FORM>
    </BODY>
    </HTML>',"600", "440", "Timezoned TimeStamping from EXIF"));

     IF ("$TimezonedEXIF"=="") {sub "_Cancel";}

     substr $TimezonedEXIF, $TimezonedEXIF, 1;

//     $tzone = gettoken($TimezonedEXIF, "1", "&");
//     $attrib = gettoken($TimezonedEXIF, "1", "&");

     $tzone = gettoken($TimezonedEXIF, "1", "&");
     $tzone = urldecode(gettoken($tzone, 2, "="));

     $attrib = gettoken($TimezonedEXIF, "2", "&");
     $attrib = urldecode(gettoken($attrib, 2, "="));

    timestamp $attrib, formatdate("<dateexif>", , "n", $tzone);

"_Cancel"
  msg "Canceled";   
   sub "_EOF"; 
"_EOF"
   END 1==1;
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: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

...and a help with the above mentioned problem regarding the Set Modified to Next Day of Current (no time) : TouchModifiedNextDay section of Touch would be welcome, too. Thanks.
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: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

Anyone able to help me with those? I'm making no progress at all...
-I can't get the HTML interface to interact with the script itself, parsing inputs and executing it.
-Can't fix this:
(problem seems to be at the "_touchAll", being called from load "", "_touchAll"; resultant from the line load ( ( $group_gbl == 1) ? ('global $tmp_gbl; $tmp_gbl = "'.$item.'"; load "'.$file.'", "_touchAll";') : "timestamp $type_gbl, ""$new_date_gbl"", ""$item"";" ),,s;; dependency Date.xys must be placed under <xyscripts>. One attempt was to set self $file, <curitem>; instead of self $file, file; - which failed, too).
Thanks!

Code: Select all

"Set Modified to Next Day of Current (no time) : TouchModifiedNextDay"
   Setting "AllowRecursion", 1;
   global $type_gbl, $group_gbl, $new_date_gbl;
   $type_gbl = "m"; // Modified
   $group_gbl = 1; // Value for all items
   $new_date_gbl = "+1m!"; // Modified + 1 day
   sub _touchStart;

"_touchStart"
   Setting "AllowRecursion", 1;
   global $list_gbl, $group_gbl;
   // set options if not done already
   sub ( $group_gbl == "" ) ? "_touchOptions" : "_nothing";
   // creates the list to work with : Full path/name and the dates of references, already formatted
   $list_gbl = report("{Fullname}{Created dd/mm/yyyyhh:nn:ss}{Modified dd/mm/yyyyhh:nn:ss}|", 1);
   // if current item in selection, move it first so it's the reference one when applied to all selected items at once
   sub (<curitem> == "") ? "_nothing" : "_touchCurItemFirst";
   // go go go
   sub _touchLoop;
   // done
   status "Timestamping complete";
"_touchOptions"
   Setting "AllowRecursion", 1;
   global $group_gbl;
   // set options : 0 = ask pattern/date for all items; 1= calculate date for first item, apply to all items; 2= apply pattern to all items (calculated for each one)
   $group_gbl = (getinfo("CountSelected") > 1) ? confirm("Do you want to touch all selected items at once ?<br><br>OK = All items at once<br>Cancel = All items individually") : 0;
   $group_gbl = ($group_gbl == 1) ? 1 + confirm("Do you want the pattern to be applied to all selected items ?<br><br>OK = Pattern, e.g. m = modified date of each item<br>Cancel = First resolved value, e.g. m = modified date of first item") : 0;
"_touchCurItemFirst"
   Setting "AllowRecursion", 1;
   global $list_gbl;
   // length of path/name
   strlen $l, <curitem>;
   // finds the item
   strpos $p, $list_gbl, <curitem>;
   // items before
   substr $bef, $list_gbl, 0, $p;
   // current item (w/ dates)  37 = dates (36) + pipe
   substr $itm, $list_gbl, $p, $l + 37;
   // items before
   substr $aft, $list_gbl, $p + $l + 37;
   // move current to top of list
   $list_gbl = $itm.$bef.$aft
"_touchLoop"
   Setting "AllowRecursion", 1;
   global $list_gbl, $item_gbl;
   // get end of item's data
   strpos $p, $list_gbl, "|";
   // extract item
   substr $item_gbl, $list_gbl, 0, $p;
   // remove it from list
   substr $list_gbl, $list_gbl, $p + 1;
   // do the work
   sub _touch;
   // continue?
   sub ($list_gbl == "") ? "_nothing" : "_touchLoop";
"_touch"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $item_gbl, $dates_gbl, $group_gbl;
   // ensure an item do timestamp
   assert ($item_gbl != ""), "No item selected !";
   // get created/modified dates
   substr $c_date, $item_gbl, -36, -26;
   substr $c_time, $item_gbl, -26, -18;
   substr $m_date, $item_gbl, -18, -8;
   substr $m_time, $item_gbl, -8;
   // for later use in loaded scripts, because I don't want to global them all...
   $dates_gbl = '$c_date = "'.$c_date.'"; $c_time = "'.$c_time.'"; $m_date = "'.$m_date.'"; $m_time = "'.$m_time.'";';
   // get item's path/name & name only
   substr $item, $item_gbl, 0, -36;
   regexreplace $name, $item, "^.+\\([^\\]+)$", "$1";
   
   // ask for new date if needed
   load ( ($new_date_gbl == "") ? ('global $type_gbl, $new_date_gbl, $group_gbl; '.$dates_gbl.' input $new_date_gbl, (($type_gbl == "m") ? "Modified" : "Created") . " ".(($group_gbl == 2) ? "pattern" : "date")." for ".(($group_gbl >= 1) ? (getinfo("CountSelected") . " selected items") : """'.$name.'""")."  |  [empty] = Now; ! = Reset time; +/-[0-9][cm]! = Maths", "$'.$type_gbl.'_date $'.$type_gbl.'_time";') : 'call'),,s;
   // trick so that an empty pattern canbe applied in batch without cause a prompt
   $new_date_gbl = ($new_date_gbl == "Now") ? "" : $new_date_gbl;
   
   // save pattern (might need to restore it once done with this item)
   $pattern = $new_date_gbl;
   
   // deal with operations ( +/- [0-9] [cm] ! )
   substr $sign, $new_date_gbl, 0, 1;
   sub ( ($sign == "+") + ($sign == "-") == 1 ) ? "_touchOp" : "_nothing";
   
   // set to modified/created date (with !-suffix to reset time)
   load ( ( ($sign == "m") + ($sign == "c") == 1 ) ? ('global $new_date_gbl; '.$dates_gbl.' substr $new_date_gbl, $new_date_gbl, 1; $new_date_gbl = "$'.$sign.'_date ".(($new_date_gbl == "!") ? "00:00:00" : "$'.$sign.'_time");') : 'call'),,s;
   
   // reset hour
   load ( ($new_date_gbl == "!") ? ('global $new_date_gbl; '.$dates_gbl.' $new_date_gbl = "$'.$type_gbl.'_date 00:00:00";') : 'call'),,s;
   
   // touching -- if group == 1 then touch all items and be done with it already, otherwise it's this one item and moving on to the next...
   self $file, file;
   load ( ( $group_gbl == 1) ? ('global $tmp_gbl; $tmp_gbl = "'.$item.'"; load "'.$file.'", "_touchAll";') : "timestamp $type_gbl, ""$new_date_gbl"", ""$item"";" ),,s;
   
   // restore for when looping -- w/ trick so that an empty pattern canbe applied in batch without cause a prompt
   $new_date_gbl = ($group_gbl == 0) ? "" : (($group_gbl == 1) ? (($new_date_gbl == "") ? "Now" : $new_date_gbl) : (($pattern == "") ? "Now" : $pattern));
"_touchOp"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $item_gbl, $date_gbl, $day_number_gbl, $tmp_gbl;
   // get created/modified dates
   substr $c_date, $item_gbl, -36, -26;
   substr $c_time, $item_gbl, -26, -18;
   substr $m_date, $item_gbl, -18, -8;
   substr $m_time, $item_gbl, -8;
   // sign
   substr $sign, $new_date_gbl, 0, 1;
   // remove sign from value
   substr $tmp_gbl, $new_date_gbl, 1;
   // get flag ( ! == reset time )
   substr $flag, $tmp_gbl, -1;
   // if flag found, remove it from value
   load (($flag == "!") ? 'global $tmp_gbl; substr $tmp_gbl, $tmp_gbl, 0, -1;' : 'call'),,s;
   // get last char, might be type (c/m)
   substr $type, $tmp_gbl, -1;
   // if type not specified, we add it
   load ( ( ($type == "m") + ($type == "c") == 0 ) ? 'global $tmp_gbl, $type_gbl; $tmp_gbl = $tmp_gbl.$type_gbl;' : 'call'),,s;
   // now get value (all minus type)
   substr $value, $tmp_gbl, 0, -1;
   // and get type
   substr $type, $tmp_gbl, -1;
   
   // get reference date
   $date_gbl = eval('$'.$type.'_date');
   // calc its day number
   load Dates, _getNumberFromDate;
   // do the maths
   $day_number_gbl = eval("$day_number_gbl $sign $value");
   // get the new date back
   load Dates, _getDateFromNumber;
   // return it, with time unless flagged to reset
   $new_date_gbl = "$date_gbl " . (($flag == "!") ? "00:00:00" : eval('$'.$type.'_time'));
"_touchAll"
   Setting "AllowRecursion", 1;
   global $type_gbl, $new_date_gbl, $tmp_gbl, $list_gbl;
   // removes dates from list
   regexreplace $list_gbl, $list_gbl, "(.+?).{36}(\|)", "$1$2";
   // remove last pipe
   substr $list_gbl, $list_gbl, 0, -1;
   // add the extracted item
   $list_gbl = ($list_gbl == "") ? $tmp_gbl : "$tmp_gbl|$list_gbl";
   // touch
   timestamp $type_gbl, $new_date_gbl, $list_gbl;
   // and done!
   $list_gbl = "";
"_nothing"
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: Touch : Set Created/Modified Dates of Selected Items

Post by SkyFrontier »

Timezoned TimeStamping from EXIF:
It seems that
<FORM method="GET" action="confirm:">
must be
<FORM method="GET" action="xys:">
, but I still can't get this thing to work (=integrate the HTML and the code/script itself). Any help is appreciated.
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