I have a bunch of folders, that have the year in (xxxx) format at the end of the filename. I have tried for the last hour or so modifying the current script, but cannot get it to read the date, any help?
Thanks in advance!
-Erik
Code: Select all
Before
Name Date modified
Crash (2004) 6/20/2011
After
Name Date modified
Crash (2004) 1/1/2004
Code: Select all
$file = "Crash (2004)";
//regex to match one-or-more of any sign, till an space, following an (, following 4 digits, following an )
$RegExFind = "^.+ \((\d\d\d\d)\)$"; //or "^.+ \((\d{4})\)$"
// that's: " ^ .+ \( (\d\d\d\d) \) $ "
//replace with what is matched by the pattern inside the parenthesis ()
$RegExReplace = "$1";
//execute the regex:
$date = regexreplace($file, $RegExFind, $RegExReplace);
//check if it works
msg "Debug: #$date#",1;
//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
msg "Debug2: 1/1/$date",1;
timestamp mc, "1/1/$date", $file;Yup, plenty good, I created a test share on my nas and copied a couple of movies over for initial trial, and works wonders! Below if the complete code in case someone else needs it. I left all the comments in for the newbs (including myself)Stefan wrote:Is it enough to provide you the needed regex?
Code: Select all
"Set date from filename"
//collect the selected files into var $fileslist:
$filelist = getinfo('SelectedItemsPathNames', '|');
//initialize loop-counter var:
$count=1;
//start an infinity loop:
while(1){
//put one file after the other into var $file:
$file=gettoken($filelist,$count,"|");
//if var $file is empty break the script:
if("$file"==""){break;}
//regex to match one-or-more of any sign, till an space, following an (, following 4 digits, following an )
$RegExFind = "^.+ \((\d\d\d\d)\)$"; //or "^.+ \((\d{4})\)$"
// that's: " ^ .+ \( (\d\d\d\d) \) $ "
//replace with what is matched by the pattern inside the parenthesis ()
$RegExReplace = "$1";
//execute the regex:
$date = regexreplace($file, $RegExFind, $RegExReplace);
//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, "1/1/$date", $file;
$count++;}
status "Done!",,ready;
beep 800,100; beep 400,100; beep 600,100;
Code: Select all
//start an infinity loop:
while(1){
//put one file after the other into var $file:
$file=gettoken($filelist,$count,"|");OK, i hear itadmin wrote:Note that this syntax construct is outdated:Since v9.90.0500 - 2011-02-21 12:00 XY supports foreach loops which makes this kind of stuff much easier to write.Code: Select all
//start an infinity loop: while(1){ //put one file after the other into var $file: $file=gettoken($filelist,$count,"|");
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 one-or-more of any sign, till an space, following an (, following 4 digits, following an )
$RegExFind = "^.+ \((\d\d\d\d)\)$"; //or "^.+ \((\d{4})\)$"
// that's: " ^ .+ \( (\d\d\d\d) \) $ "
//replace with what is matched by the pattern inside the parenthesis ()
$RegExReplace = "$1";
//execute the regex:
$date = regexreplace($file, $RegExFind, $RegExReplace);
//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, "1/1/$date", $file;
}
status "Done!",,ready;
beep 800,100; beep 400,100; beep 600,100;
Code: Select all
"Set date from filename"
foreach( $file, get('SelectedItemsPathNames', '|') ) {
$YEAR = regexreplace($file, "^.+ \((\d\d\d\d)\)$", "$1");
timestamp mc, "1/1/$YEAR", $file;
}
status "Renaming done!",,ready; beep 800,100; beep 400,100; beep 600,100;
Code: Select all
//if var $file is empty break the script:
if("$file"==""){break;}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.
That is REALLY short, and works fine, thanks again!Stefan wrote: or in short
Code: Select all
"Set date from filename" foreach( $file, get('SelectedItemsPathNames', '|') ) { $YEAR = regexreplace($file, "^.+ \((\d\d\d\d)\)$", "$1"); timestamp mc, "1/1/$YEAR", $file; } status "Renaming done!",,ready; beep 800,100; beep 400,100; beep 600,100;