[Newbie] Complicated bulk renaming script

Advanced Renamer forum
#1 : 15/05-22 18:41
Pheggas
Pheggas
Posts: 1
Hello. Some time ago, i downloaded Advanced Renamer as i wanted to set timestamp of image based on it's date in filename. That was pretty easy altho i had some issues.

Now i have over 250 recordings from school in format <YYYY>-<MM>-<DD> <HH>-<mm>-<ss>. From this format i want to determinate which day in week it was (Monday through friday) and based on combination of time and day in week i want to set name in format of <Subject name> <type: lecture or exercise> <Date>, so i can then easily determinate what exactly i want to play / watch.

I'm pretty sure it is possible with Advanced Renamer but my skill is on freezing point so i would appreciate some help. I didn't find any template to determine day of week based on date yet.

Anyone help?


15/05-22 18:41
#2 : 15/05-22 23:21
David Lee
David Lee
Posts: 961
You haven't provided enough information to give a complete solution to your problem.
However it is a simple matter to extract the day of the week from the date string in your filenames using a script.

First parse the date string into its individual components using the match method and a regular expression, which will return an array where the entire match is saved in element [0] and YYY, MM, DD ,hh, mm, ss into elements [1] to [6].

Then create a JavaScript Date object "date" from which you can extract the day of the week as an integer (0 - 6) using date.getDay()

Finally use a lookup table to convert the integer to the name of the day.

So create a script method and save the following code in the Pre batch script:

days = new Array(7);
days[0] = "Sunday";
days[1] = "Monday";
days[2] = "Tuesday";
days[3] = "Wednesday";
days[4] = "Thursday";
days[5] = "Friday";
days[6] = "Saturday";

Then enter this code into the main script window:

D = item.name.match(/(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})/);
if (D) {
date = new Date(D[1], D[2], D[3], D[4], D[5], D[6]);
return days[date.getDay()] + "-" + D[0];
}

Assuming that your filenames begin with the date, this code will add the day of the week to the beginning of each filename.

eg "2012-05-06 10-06-30#qwerty" -> "Wednesday-2012-05-06 10-06-30#qwerty"

The if statement: "if (D) { ... }" prevents an error occurring in case the filename does not contain a valid date string (in which event the match would return NULL instead of an array and crash the script).





15/05-22 23:21 - edited 15/05-22 23:22