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"
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"