Hi Paul, welcome to the community!
Let me explain a little more since this seams to be an task of common interest.
According to my editing above there is an slightly new syntax and better commands to build this script
as i have written over there >>
http://www.xyplorer.com/xyfc/viewtopic. ... 678#p60678
But I will post it here below again, modified for your example.
That script below can be used for all kind of file names,
only the RegEx (regular expression pattern) has to be adjusted to match the time and date.
I will show here how as an example:
For your string
"2007-11-17 t10-32-50 dv10mac04.avi"
we have to split that into several parts to match the different time and date pattern.
First match start of string by an RegEx meta sign => ^
Then match 4 digit for year => \d\d\d\d
Put that match into parentheses (...) to refer to it later in replacement => (\d\d\d\d) by using $1 there for the first ()-group
match an hyphen literally => -
match two digits => \d\d ==> and store it in group $2 ===> (\d\d)
match an hyphen literally => -
match two digits => \d\d ==> and store it in group $3 ===> (\d\d)
match an blank
match an t
match two digits, hyphen, two digits, hyphen, two digits => (\d\d)-(\d\d)-(\d\d)
match an blank and then the rest of string till end => .+$
Note: things we don't need for replacement we don't match in parentheses because we drop them anyway
So for
"2007-11-17 t10-32-50 dv10mac04.avi"
we build an RegEx like:
^(\d\d\d\d)-(\d\d)-(\d\d) t(\d\d)-(\d\d)-(\d\d) .+$
and our XYplorer string looks like:
$RegExFind = " ";
$RegExFind = "^(\d\d\d\d)-(\d\d)-(\d\d) t(\d\d)-(\d\d)-(\d\d) .+$";
Note that we can shorten that RegEx by using
\d{4}
instead of
\d\d\d\d
and build the regex like
$RegExFind = "^(\d{4})-(\d{2})-(\d{2}) t(\d{2})-(\d{2})-(\d{2}) .+$";
but that looks even more worse and didn't save much.
How to build the
$RegExReplace string is depending on your local settings.
Here is an excerpt from the timestamp() help
//add day and month as you need for your local settings:
//timestamp [type], [date], [itemlist]
//type [optional] c|m|a or any combinations in any order (cm, am, cma, ac...); defaults to cma
//date [optional] must be in a format that the local system can understand
//timestamp mc, "<date yyyy-mm-dd> 12:00:00", "C:\Test.txt|C:\Test2.txt"
timestamp mc, "1/1/$date", $file;
Note that "$date" is set into quotes.
So you have to build the $RegExReplace string at your own:
We have matched 6 parts from the file name and hold them into groups, named $1 to $6
$1 will hold the year
$2 the month
$3 the day
$4 the hour
$5 the minutes
$6 the seconds
As $RegExReplace string, for example use something like:
timestamp mc, "$3/$2/$1 $4:$5:$6", $file;
or
timestamp mc, "$1-$2-$3 $4:$5:$6", $file;
or
what ever order match
when you open DOS-Box and type in
date /t <ENTER>
time /t <ENTER>
You see, you can refer to the content matched and stored into ()-groups by $n syntax
and by any order and by adding any new signs as you need.
You can even get an output like: "It was $6 seconds after $4:$5 on $3.$2 of the year $1, as i produced my first million of revenue"
So here is the script with new foreach() command and new syntax like get() instead of getinfo()
Code: Select all
"Set date from filename"
//////collect the selected files into var $fileslist:
$filelist = get('SelectedItemsPathNames', '|');
//////foreach($variable, listoftokens, [separator=|])
foreach( $file, $filelist) {
//////regex to match
$RegExFind = "^(\d\d\d\d)-(\d\d)-(\d\d) t(\d\d)-(\d\d)-(\d\d) .+$";
//////add day and month as you need for your local settings:
//////timestamp [type], [date], [itemlist]
//////type [optional] c|m|a or any combinations in any order (cm, am, cma, ac...); defaults to cma
//////date [optional] must be in a format that the local system can understand
//////timestamp mc, "<date yyyy-mm-dd> 12:00:00", "C:\Test.txt|C:\Test2.txt"
//////replace with what is matched by the pattern inside the parenthesis ()
$RegExReplace = "$1-$2-$3 $4:$5:$6";
//////execute the regex:
$date = regexreplace($file, $RegExFind, $RegExReplace);
//////set new timestamp:
timestamp mc, "$date", $file;
}
status "Done!",,ready;
beep 800,100; beep 400,100; beep 600,100;
or in short
Code: Select all
"Set date from filename"
////////////// user settings:
////// RegEx to match YYYY-MM-DD tHH-NN-SS out of: "2007-11-17 t10-32-50 dv10mac04.avi"
////// and store into groups named from $1 to $6 from left to right.
$RegExFind = "^(\d\d\d\d)-(\d\d)-(\d\d) t(\d\d)-(\d\d)-(\d\d) .+$";
////// RegEx to build an $DATE in a format that the local system can understand
////// by reorder the $n groups:
$RegExReplace = "$1-$2-$3 $4:$5:$6";
/////////////code for each selected file:
foreach( $file, get('SelectedItemsPathNames', '|') ) {
$DATE = regexreplace($file, $RegExFind, $RegExReplace);
timestamp mc, "$DATE", $file;
}
//////the end, inform the user that it is over:
status "Renaming done!",,ready; beep 800,100; beep 400,100; beep 600,100;
- - -
Some explanations:
1.)
Please note that the command get
info() is officially renamed to get() long ago
2.)
I see that that is not needed anymore:
Code: Select all
//if var $file is empty break the script:
if("$file"==""){break;}
because of:
Help wrote:get("SelectedItemsPathNames");
Note that before v9.40.0007 the separator was actually a delimiter (i.e. it was returned after each item, not between the items.
- - -
HTH?

and i have not mixed things up to much.
-- 850 --