Page 1 of 1

Adding a range of dates to group of files

PostPosted: Fri Jun 11, 2021 6:47 pm
by cjreynolds
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

Re: Adding a range of dates to group of files

PostPosted: Fri Jun 11, 2021 7:21 pm
by Luuk
This could be very possible with the paid version and using the javascript, but sorry Im not expert to advise on this code.

Re: Adding a range of dates to group of files

PostPosted: Fri Jun 11, 2021 7:37 pm
by cjreynolds
Excellent! Can Do!

Thanks! (you made my day when you said "javascript", LOL!)

Re: Adding a range of dates to group of files

PostPosted: Fri Jun 11, 2021 10:53 pm
by Luuk
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.