Adding a range of dates to group of files

Bulk Rename Utility How-To's

Adding a range of dates to group of files

Postby cjreynolds » Fri Jun 11, 2021 6:47 pm

I need to add as prefixes a range of dates to a group of MP3 files - not extracted from the file properties, just a date range that I determine - ie: 2021-07-01 thru 2021-08-01 (excluding weekends) or 2021-07-01 thru 2021-08-01 (sundays only). In reading the helpfile, it seems that the only option is to extract date info from the files and using that, but I need to specify my own date ranges, irrespective of the files' encoded date info. Is this possible?

Thanks,
Joe Reynolds
cjreynolds
 
Posts: 2
Joined: Fri Jun 11, 2021 6:29 pm

Re: Adding a range of dates to group of files

Postby Luuk » Fri Jun 11, 2021 7:21 pm

This could be very possible with the paid version and using the javascript, but sorry Im not expert to advise on this code.
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Adding a range of dates to group of files

Postby cjreynolds » Fri Jun 11, 2021 7:37 pm

Excellent! Can Do!

Thanks! (you made my day when you said "javascript", LOL!)
cjreynolds
 
Posts: 2
Joined: Fri Jun 11, 2021 6:29 pm

Re: Adding a range of dates to group of files

Postby Luuk » Fri Jun 11, 2021 10:53 pm

This an example using 07-01-2021 for a start-date, and being prejudice against the weekends...
Code: Select all
start = new Date(2021,06,00);
function nextWorkDay(start, counter) {   
  while (counter > 0) { start.setDate(start.getDate() + 1);
                     if (start.getDay() != 0 && start.getDay() != 6) { counter -= 1 }
                    }
  return start }
newName = nextWorkDay(start, counter) + '___' + name
But this output is very terrible looking, because the dates get invented looking like this...
Thu Jul 01 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File1.txt
Fri Jul 02 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File2.txt
Mon Jul 05 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File3.txt
Tue Jul 06 2021 00:00:00 GMT-0700 (Pacific Daylight Time)___File4.txt


So for me, Im just downloaded the "moment.js" because then its much easier to format the dates with...
Code: Select all
require('js/moment.js')
start = new Date(2021,06,00)
function nextWorkDay(start, counter) {   
  while (counter > 0) { start.setDate(start.getDate() + 1);
                     if (start.getDay() != 0 && start.getDay() != 6) { counter -= 1 }
                    }
  return start }
newName =  moment(nextWorkDay(start, counter)).format('YYYY-MM-DD') + '___' + name
So then its not so bad, because now looking more like...
2021-07-01___File1.txt
2021-07-02___File2.txt
2021-07-05___File3.txt
2021-07-06___File4.txt

Except still this code will not use 08-01-2021 as the last-date in your range, so if you can modify, please do post the solution.
Im just copied the function from stackexchange, and then modified the variables, but not really understanding how it conducts.
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To