SkyFrontier wrote:
turn into this:
Code: Select all
C_2001-0829_15hr26min02_M_2009-0819_15hr26min06_keyremapper_setup.txt
...
Code: Select all
"Rename file to add C+M timestamp"
end(getinfo("CountSelected") < 1), "Please select some files first.";
rename b, "C_"."<datec yyyy-mmdd_HH>"."hr"."<datec NN>"."min"."<datec SS>"
."_M_"."<datem yyyy-mmdd_HH>"."hr"."<datem NN>"."min"."<datem SS>_*";
status SUCCESS!;
"Set timestamp from file name"
end(getinfo("CountSelected") < 1), "Please select some files first.";
$Records = getinfo("SelectedItemsPathNames", "|");
$LOOP=1;
while(1){
$RecSet = gettoken($Records, $LOOP, "|");
if ($RecSet==""){break;}
$cDate = regexreplace($RecSet, ".+C_(.+)_M_(.+)_.+", "$1");
$cDate = regexreplace($cDate, "(\d\d\d\d)-(\d\d)(\d\d)_(\d\d)hr(\d\d)min(\d\d)", "$3/$2/$1 $4:$5:$6");
timestamp c, $cDate, $RecSet;
$mDate = regexreplace($RecSet, ".+C_(.+)_M_(.+)_.+", "$2");
$mDate = regexreplace($mDate, "(\d\d\d\d)-(\d\d)(\d\d)_(\d\d)hr(\d\d)min(\d\d)", "$3/$2/$1 $4:$5:$6");
timestamp m, $mDate, $RecSet;
incr $LOOP;
}
status DONE!;
------------
Explanation:
"Rename file to add C+M timestamp"
renames an file
"LESER.txt"
to
C_2010-0820_09hr06min01_M_2009-0112_10hr28min23_LESER.txt
by adding creation and modification timestamp in front of the original file name.
------
"Set timestamp from file name"
gets the full path with "SelectedItemsPathNames" since timestamp() wants this.
$cDate = regexreplace($RecSet, ".+C_(.+)_M_(.+)_.+", "$1");
means:
.+ ==> all signs till an "C_" ==> e.g. "X:\path\folder\"
C_ ==> match "C_"
(.+)_ ==> match all signs till an underscore "_" ==> "2010-0820_09hr06min01" ==> stored in (...)-group 1
M_ ==> match "M_"
(.+)_ ==> match all signs till an underscore "_" ==> "2009-0112_10hr28min23" ==> stored in (...)-group 2
.+ ==> match all signs till the end ==> "LESER.txt"
"$1" returns what is matched and stored in group 1 ==> "2010-0820_09hr06min01"
The second
$mDate = regexreplace($mDate, "(\d\d\d\d)-(\d\d)(\d\d)_(\d\d)hr(\d\d)min(\d\d)", "$3/$2/$1 $4:$5:$6");
matched the digits groups for year, month and day,...
(\d\d\d\d) ==> "2010" ==> backreference group $1
-
(\d\d) ==> "08" ==> backreference group $2
(\d\d) ==> "20" ==> backreference group $3
_
(\d\d) ==> "09" ==> backreference group $4
hr
(\d\d) ==> "06" ==> backreference group $5
min
(\d\d) ==> "01" ==> backreference group $6
and rearrange this matched groups in an new order,
and also adds some typical signs for the timestamp() command ==> "$3/$2/$1 $4:$5:$6"
Sorry, no time to explain it better. An RegEx tutorial and XYplorers debug dialog is everybody friend
------------
------------
------------sidenote:
I have tried to use this too:
Code: Select all
rename b, "C_<datec yyyy-mmdd_HH>hr<datec NN>min<datec SS>
_M_<datem yyyy-mmdd_HH>hr<datem NN>min<datem SS>_*";
but this doesn't work while i get:
C_2010-0820_09hr06min
20.08.2010 09:27:26 26_M_2009-0112_10hr28min8 26_*
It seams i tricked the parser out?