#1 : 23/04-22 17:23 Doug Fullerton
Posts: 2
|
I have files named as such:
(OAT_MMDDYY_P01.pdf) format OAT_042422_P01.pdf actual filename how can i make it for OAT_042322_P01.pdf also so that the 1st of the month will then revert to the 30th or 31st? thanks for any guidance on this! |
#2 : 24/04-22 13:02 David Lee
Posts: 1125
|
Note also that the 1st Jan will also revert to 31st Dec in the previous year and you will also need to take care of leap years.
Best way is to use a script. Extract the components of the date using a regular expression and subtract 1 from the day number Then create a Date variable using new Date(yyyy, mm, dd) Extract year, month and day from the Date variable. A small complication is that JavaScript numbers months from Jan = 0 so you need to subtract 1 from the original month number and the add it back at the end. The following script will work for dates from 2000... match = item.name.match(/([^_]*_)(\d{2})(\d{2})(\d{2})(.*)/); y = 1*match[4] + 2000; m = 1*match[2] - 1; d = 1*match[3] -1; date = new Date(y, m, d); y = date.getFullYear(); m = date.getMonth() + 1; d = date.getDate(); return match[1] + ("0" + m).slice(-2) + ("0" + d).slice(-2) + y.toString().substring(2) + match[5] |
#3 : 03/05-22 21:54 Doug Fullerton
Posts: 2
|
Reply to #2:
Not sure what i'm doing wrong but the preview is showing this: Filename OAT_050122_P01.pdf New Filename OAT_0501OAT_22_P01.pdf Not sure why it's adding the OAT_ prefix again? thanks! |
#4 : 03/05-22 23:45 David Lee
Posts: 1125
|
Reply to #3:
I've just checked the script and it is returning OAT_043022_P01 as expected. Copy and paste my original code into the Script window and try again. Make sure that the Pre-batch script is blank. |