Change todays date in tomorrows date

Advanced Renamer forum
#1 : 27/07-24 05:52
GSComputer
Posts: 33
I have a files like:

filename_2024-07-20.txt
filename_2024-07-21.txt

and want to change it in:

filename 21.07.2024
filename_22.07.2024

I want to to increase a date's day in one day later (e.g.today in tomorow)

Which method will help? it should be increment, but I can't find a way to handle it
#2 : 27/07-24 06:48
Delta Foxtrot
Posts: 292
Reply to #1:

Hi GS,

It's easy with two methods. I'm sure it's possible in one but this is dead bang easy.

RENUMBER METHOD:
Number position: 3
Change to: Relative
Number difference: 1
Zero padding: No padding, although any setting would probably work
Apply to: Name

That gets you the incremented day date. Then just move date-numbers around:

REPLACE method:
Replace: (\d{4})-(\d{2})-(\d{2})
Replace with: $3.$2.$1
Use regex CHECKED
(no spaces in the fields, of course)

EDIT: I just noticed your "after" filenames are different; one has a space and one has an underscore. If you want the underscore use the above. If you want a space in its place just change the "Replace:" string to "_(\d{4})-(\d{2})-(\d{2})" and the "Replace with:" string to " $3.$2.$1" (no quotation marks). END EDIT

Best,
DF

edited: 27/07-24 07:03
#3 : 27/07-24 09:20
GSComputer
Posts: 33
Reply to #2:
Reply to #2:
Hi DF,

that works. but.......

I use this in a method list and filename has different Length and names. With always the same name of the filename it works. I use it for renaming Newspapers.
e.g.
Sunday Newspaper FAZ 2024-07-27 should be incremented because it is with date Saturday
Newspaper FAS 2024-07-28 should not be incremented because date is ok
newspaper Post on Sunday 2024-07-27 should be incremented because it is with date Saturday

I use one list for all newspapers. I have no problem with replace method. The renumber in one list only to determined Filenames and not the dates of other newspapers

It's The combining The newspaper Name with date. Something like IF --Then
IF filename is xy.txt THEN Renumber

I know it's a luxery Problem.
Best
GS
#4 : 27/07-24 11:30
Delta Foxtrot
Posts: 292
Reply to #3:

Hi GS,

Sorry that didn't work for you. That's why it's important to include all the context information you can. :)

Assuming those files are a representative sample, this script will look for "sunday" extract the day, increment it, and replace with the incremented number. It's a dumb script because it doesn't parse out the end of month, so if Saturday falls on Feb 28, for instance, welcome to leap year! :)

This shouldn't effect anything but filenames with the word Sunday, in which the date falls at the end of the filename with the format "YYYY-MM-DD". If there's some other complication hit me back with the details.

SCRIPT:
---------------------------------------------------------------------
*** DEPRECATED ***
----------------------------------------------------------------------
Best,
DF

edited: 29/07-24 01:59
#5 : 27/07-24 12:37
GSComputer
Posts: 33
Reply to #4:
Hi DF,

I will try your solution with the script next week.
First I have to learn to understand the script to use it with my german names.

This weekend my three granddaughters visit me and I have to take care of them :-)

Meanwhile I work on a solution to Move the Files to be renumbered to another directory, where I can renumber them in the way you showed me and move them back after they are renumbered.
Is not elegant, but it will work.
Like I already said it's a "minor luxorary" problem., but I want to solve it. In my (our) age it is better to solve such problems than to sit in front of the TV and watch soaps or old movies.
As a retired Technical Officer in The German Airforce I'm first satisfied when problems are solved.
I keep you informed.
Thanks so far for your help
Best wishes
Gerhard


edited: 27/07-24 12:39
#6 : 27/07-24 18:14
Delta Foxtrot
Posts: 292
Reply to #5:

Hey GS,

Enjoy those grandchildren. Priorities, my friend! :)

The script is easy to understand. I've entered it below with my original comments to myself, plus a little for you.
**** EDIT: DO NOT USE THIS SCRIPT ****
// First we define the variables we will need:
// fname is the filename passed to the script each iteration
// (and what we'll modify to return as the new filename, if necessary
// index is just a number to hold the numeric position in the filename
// of the first letter of the word "sunday"
// day is the day number (as string) we strip from the filename.
// nameStart is all the filename before the start of the date string.
// newday is the new day number, as a string,
// that we graft back onto the "nameStart" filename chunk

var fname, index, day, nameStart, newday ;

// grab the filename into fname:
fname = item.newBasename ;

// search fname for the string "sunday" (case insensitive)
// and note its position in the string in "index".
index = fname.search(/sunday/i );

// if "sunday" is not present index will be -1, otherwise it's 0 or greater.
if ( index > -1 ) {

// "sunday" was found; we must add 1 to day number.
// pull the old day number string into the "day" variable.
// Negative number means count from the tail end of the filename:
day = fname.substr( -2 ) ;

// grab the rest of the filename, minus day number string, into "nameStart":
nameStart = fname.substr( 0, (fname.length - 2) ) ;

// convert day number string to integer, add 1, then make that number a string
// and place in var "newday":
newday = (parseInt(day)+1).toString() ;

//graft new day string onto "nameStart", put in "fname" and go home:
fname = nameStart + newday ;
}
// "fname" now contains our filename - whether modified in the IF statement or just
// left the same as when this iteration began.
// coffee break!
return fname ;
--------------------------------------------------------------------------------
I think the only thing you'll need to convert is the literal string "sunday" in the line where we search for it. I can't swear to it, but I assume javascript keywords are the same all over.

I hope this helps,
DF

edited: 29/07-24 02:00
#7 : 27/07-24 18:48
Miguel
Posts: 140
Reply to #4:
Hello
I know that no matter how complicated it is, you always have the solution with yours incredible scripts.

But from my ignorance, loading the files that only contain the word Sunday using a wildcard like *Sunday*.* and then proceeding to use your first method with Renumber and Replace wouldn't do the same?

Miguel
#8 : 27/07-24 19:15
Delta Foxtrot
Posts: 292
Reply to #7:

Hi Miguel,

It's my understanding that he has a batch with lots of other methods that work on the files in other ways. This way he could just add the script method to his batch and have it only work on the files in question, while other methods work on other files.

I don't know... I just wrote the script as practice anyway. I'm not even sure that Sunday is the only thing he needs to look for, but... it's a process, right? :)

Check out post #3 above for GS's description of the problem, and why the first solution isn't optimum.

Best regards,
DF
#9 : 28/07-24 03:22
GSComputer
Posts: 33
Reply to #8: and #7
Hi DF and Miguel,

DF has really understood my "Little" problem. It's because the batch has lots of other metods.
Sunday is not the only criteria, that's only an excample.
@Miguel
Sure your way works like it should, thats the way I use it in the moment. The script would be an automatic solution. Therefoer I will try this next week. I used AR without scripts yet and i'm interested in learning and understanding it.
Also I noticed that I use to less the regex. Im looking for a description for that.

I love this forum and the helpful guys like you Sometimes the forum helps me to see problems, what I didn't know I have them -:-)

Thanks both for your help

#10 : 28/07-24 05:22
Delta Foxtrot
Posts: 292
Reply to #9:

Hi GS,

As long as your other criteria occur as unique strings in your filenames you can just change the line:

index = fname.search(/sunday/i );

to:

index = fname.search(/(sunday|saturday|late ed|whatever)/i );

Inside the forward slashes add parenthesis open & close around your search strings and separate each string with a | symbol ("pipe") and the script will search for whatever you put there. Shouldn't matter if you have more than one in a single filename, it just needs to make a match to change the date.

Cheers,
DF
#11 : 28/07-24 05:46
GSComputer
Posts: 33
Reply to #10:
Hi DF

The excample.l filename is: WELT am Sonntag 26.07.2024.pdf
German Format DD.MM.YYYY

With your Format YYYY-MM-DD it works perfect.

I didn't get the increase on the Day

I tried -8 -10 it frome the end of the file. But it doesn't increase DD but YYYY
It should be easy, but I don't see it.
It#s too early here 05:30am (Senile Bed Escape)
Thanks for your patience
#12 : 28/07-24 06:11
Delta Foxtrot
Posts: 292
Reply to #11:
Here you go GS:
EDIT: **** DO NOT USE THIS SCRIPT ****
var fname, index, day, month, year, nameStart, newday ;
fname = item.newBasename ;
index = fname.search(/(sunday|sonntag|late ed)/i );
if ( index > -1 ) {
year = fname.substr( -4 ) ;
month = fname.substr( -7, 2 );
day = fname.substr( -10, 2 );
nameStart = fname.substr( 0, (fname.length - 10 ) ) ;
newday = (parseInt(day)+1).toString() ;
fname = nameStart + newday + "." + month + "." + year ;
}
return fname ;
I had to carve out the date parts and then reassemble them, but it's basically the same script. Next time let's start with the actual information. :)
Screenshot: https://drive.google.com/file/d/1ZECheKXLx_tZjpS MQbuDK7sXfynh1oNG/view?usp=sharing
Don't drink too much coffee. I'm just going to bed, so later alligator.

Best wishes to you and yours. Maybe you should encourage your granddaughters to learn to code, they'll be better at it than I am, I'm sure! :)

DF

edited: 29/07-24 02:01
#13 : 28/07-24 10:09
GSComputer
Posts: 33
Reply to #12:

Hi DF,
I was too nosy not try the the script.
I adapted the script to my expressions (Filenames) tread your descriptions in'#6 and went through it in all steps. Now I understood this script. You explained that very well.
Thanks a lot.
Til next prob
Bye
GS
#14 : 28/07-24 17:41
Delta Foxtrot
Posts: 292
Reply to #13:

Hey GS,

Glad it works for you. That didn't stop me from worrying about the problems–end of month, end of year, and February leap year awareness (or rather lack of).

This script hopefully takes care of those problems. It knows when a day-increment takes you into the next month and into the next year, and it knows when 29.02.nnnn falls in a leap yeaer and is a valid date.
Use it or not, I had to write it just as an exercise.
EDIT: ****** DO NOT USE THIS SCRIPT. IT IS BROKEN. SEE FOLLOWING POSTS ******
------------------------------------------------------------------------------------
PRE-BATCH SCRIPT: (could be placed at the start of the main script if desired)
const deltaDay = 1 ;
-------------------------------------
MAIN SCRIPT:
var fname, index, nameHead, day, month, year, date, D, M, Y ;
fname = item.newBasename ;
/*
Change the char string in inner parens to whatever search terms you need
for changing the day. Make sure there is a "pipe" character "|" between
each string:
*/
index = fname.search(/(sunday|sonntag|late ed|saturday|samstag)/i ) ;
if ( index > -1 ) {
match = fname.match(/^([^\d]*)(\d{2})\.(\d{2})\.(\d{4})/) ;
if (match) {
nameHead = match[1];
D = 1*match[2] ;
M = 1*match[3] ;
Y = 1*match[4] ;
D += deltaDay ;
// Determine if the month or year needs to be incremented:
if ( ( M == 1 || M == 3 || M == 5 || M == 7 || M == 8 || M == 10 || M == 12 ) && D == 32 ) {
// month has 31 days and we're over the limit; increment month, day to 1:
M++ ;
D = 1 ;
if ( M == 13 ) {
// Happy New Year!!!
M == 1 ;
}
}
// check for February month-end and leap year:
if ( M == 2 && D == 29 ) {
M = 3 ;
D = 1 ;
}
if ((Y % 4 == 0) && (Y % 100 != 0) || (Y % 400 == 0)) {
M = 2 ;
D = 29 ;
}
if ( ( M == 4 || M == 6 || M == 9 || M == 11 ) && D == 31 ) {
// Month has 30 days, and time to inc. month:
M++ ;
D = 1 ;
}
// Time to "stringify" the date and poke it into the return filename:
date = new Date(Y, M, D);
year = date.getFullYear() ;
month = date.getMonth() ;
day = date.getDate() ;
fname = nameHead + ( "0" + day ).slice(-2) + "." +
( "0" + month ).slice(-2 ) + "." + year ;
}
}
// Ah! Coffee time again!
return fname ;
------------------------------------------------------------------------------------
(Thanks once again to javascript monster David Lee who laid the groundwork for me)
This *should* work fine in method lists with other methods. EDIT: Be sure to test thoroughly before trusting the results and, as always, don't forget the UNDO procedure is always available. END EDIT
Here's some results I got:
https://drive.google.com/file/d/1EK-zZsNWiZIf3G8 drIdlqowS3TUxE3tf/view?usp=sharing
Best,
DF

edited: 29/07-24 02:04
#15 : 28/07-24 20:44
GSComputer
Posts: 33
Reply to #14:
Hello again to Texas,
I have good vibes and memories to San Antonio, sitting at riverside in beautiful restaurants, drinking lots of beer. (1974)
Hi DF,
I already thought about this problem, but didn't dare to ask you :-;
But I think you have e
fun coding and solving problems
First tries I couldn't find failures (changing system Date aso)

I have one Wish: Is it possible to search for "Welt am Sonntag" not only "Sonntag"
The search string should be "WELT" AND "am" AND "Sonntag" together

With "Sonntag" I noticed The script tries to Increase EURO 2024 30 (YYYY 30 is the weeknumber)?
Newname then EURO am SonntNaN.20.4 30 instead staying EURO am Sonntag 2024 30
I tried your first script with AR 4 The second one first ran now it is invalid AR all is red.
I go to sleep, tomorrow with clenhead I will try again

Be sure I will learn about javascript. My coding basics were in the beginning eighties (Machinery and and other easy languages) later a bit VBA for Microsoft office. But I forgot the most.

I#m sure there's an easy solution for the AND-linking.
Thanks
Gerhard

edited: 28/07-24 21:54
#16 : 28/07-24 23:09
Delta Foxtrot
Posts: 292
Reply to #15:

Hey Gerhard,

EDI T: I found another problem. Please send me screenshots, but don't actually rename any files until I get this worked out. Thanks. END EDIT

San Antonio is just down the road from me, I love it too. Now that Austin has gone to h3|| it's probably the best big city in Texas. I'm afraid my only visits to Deutschland were short layovers on the way to Greece, but I've got to say the area around Frankfurt was truly stunningly beautiful from the air. I wish I could have seen more of it.

EDIT: Anyway, you should be able to just enter the phrase "welt am sonntag" (without the quotes) as a search string in the match() statement, for example:
index = fname.search(/(sunday|welt am sonntag|late ed|saturday|samstag)/i ) ;
I used "late ed" as a search criterion in my examples; the space(s) are just another character to the regex engine. END EDIT Between the slashes everything is just a regular expession, so pretty much anything you can use in, say, a REPLACE method with regex would be usable there.
-----------------------------------------------------------------
EDIT: Try using the statement:
match = fname.match(/^(.*)(\d{2})\.(\d{2})\.(\d{4})$/) ;

In place of the line:
match = fname.match(/^([^\d]*)(\d{2})\.(\d{2})\.(\d{4})/) ;

That may cure the problem. I realized I didn't tie the date to the end of the filename.
END EDIT
-----------------------------------------------------------------
Can you include some example complete filenames? A screenshot of the problem(s) in Advanced Renamer showing the files list with "Filename" and "New Filename" columns, would be a big help. It's hard to respond for certain to something I can't see. :(

The "NaN" in the replacement shouldn't be happening; it means that the script engine is finding something "Not a Number" where it expects numbers, but it shouldn't be showing up in the results. You usually see it only in the console in response to debugging information. Do you have files mixed in that don't end with the nn.nn.nnnn pattern? If so I'd need to know, because that's where the script expects to find

When you get results in red, check the error column and let me know what you see there, or better get a screenshot. Also, I've found that I get some errors that can be cured by re-sorting the filenames (click once or twice on the "Filename" column header).

You're right, I do like doing this stuff, especially now that it's not required for work. :)

Best,
DF (Daniel)

edited: 29/07-24 00:04
#17 : 29/07-24 01:45
Delta Foxtrot
Posts: 292
Reply to #16:

Gerhard,

Pretty sure I got the insects scrubbed out of the relays, but this thread is getting really long so I'm going to post the script in a new thread. Heading will be: "INCREMENT DATE when search phrase found (for GSComputer)"

See ya there!
DF