#1 : 29/07-24 01:57 Delta Foxtrot
Posts: 339
|
Yo G,
Ok, this should do pretty much what you need. Some of the date functions in AR 4.0b seem to be a little weird so I wrote them out; also my leap year logic wasn't bulletproof before. I'm pretty sure this will fix those problems. You just need to edit the "index = fname.search(…) ;" line (line 5 on my computer) and change to use your search terms/phrases. Pre-batch stays the same: const deltaDay = 1; REWORKED MAIN SCRIPT: var fname, index, nameHead, day, month, year, D, M, Y ; fname = item.newBasename ; // Search expressions go in following line between inner parenthesis, separate by pipe "|": index = fname.search(/(welt am sonntag|late ed|saturday|samstag)/i ) ; if ( index > -1 ) { match = fname.match(/^(.*)(\d{2})\.(\d{2})\.(\d{4})$/) ; if (match) { nameHead = match[1]; D = (1*match[2]) + deltaDay ; M = 1*match[3] ; Y = 1*match[4] ; // 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 ; ++Y ; } } // check for February month-end and leap year: if ( M == 2 && D == 29 ) { ++M ; 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: year = Y.toString() ; month = ("0" + M.toString()).slice( -2 ) ; day = ("0" + D.toString()).slice( -2 ) ; fname = nameHead + day + "." + month + "." + year ; } } return fname ; ----------------------------------------------------------------------------------------------- Give it a try, and let me know how it is on your filenames. Best regards, DF |
#2 : 29/07-24 02:13 Delta Foxtrot
Posts: 339
|
Reply to #1:
Screenshot: https://drive.google.com/file/d/1B17uuSHgycUvRE7 D8gnC3p8vzqB3qC79/view?usp=sharing |
#3 : 29/07-24 05:58 GSComputer
Posts: 36
|
Reply to #1:
Hello DF you are THE BEST. This script runs perfect now. No errors, nothing red. Everything like it should. The Problem was the pre-batch You wrote in #14 in the old thread PRE-BATCH SCRIPT: (could be placed at the start of the main script if desired) const deltaDay = 1 ; I translated "if desired" with "not absolutely neccessary, it's a goodie" After inserting it in line 3 --> works like written above: can you give me an hint what it does and why it is a must? I will go through each line of the script to understand why you coded this way. Slowly but in the last edges of my brain I find memories what I learnt decades ago. I'm beginning to get fun with learning scripting. Can you recommand a handbook or handout? Would like to drink a GERMAN BEER with you. Best wishes Gerhard |
#4 : 29/07-24 07:12 Delta Foxtrot
Posts: 339
|
Reply to #3:
Hello G, Glad it works for you. Makes my little efforts worthwhile! As to that line in the pre-batch: The main script runs once for each filename, so it can execute hundreds or even thousands of times, whereas the pre-batch just runs one time. Anything that doesn't need to be re-evaluated for each filename can be put in pre-batch, which can save a lot of time and computer cycles for an intensive script. In this case the savings would be slight if that statement is in pre-batch, which Is why I said (meant) that it was ok to put it in the main section. That line just defines a javascdript "constant" (const), "deltaDay," as the number 1, that the main script references but never changes. Therefore it's perfect for pre-batch, but can also be define and populated in the main section for each filename. That constant, deltaDay, is the number of days to change the selected filename day, so it's really not necessary at all, I could have written the line "D = (1*match[2]) + deltaDay ;" as "D = (1*match[2]) + 1 ;" or "D = (1*match[2])++ ;" and it would work the same. The difference is that if I ever want to modify the script to, say add or subtract a week from a day value I I don't have to search through the script trying to remember where to find the values to change. Again, not a big deal in a little script like this, but it's a convention that's good to use consistently. I have written some scripts that have maybe 6 or 8 constants that can be changed to vary (for instance) what word in the filename to move and what position to place it, etc. At that point it's almost essential to do it this way. It's probably more common (at least for me) to use pre-batch to, say, load data from a file for reference, or to just define an array of data that the main section looks to for information about changes to the filename. Probably more information than you were looking for, right? :) As to a handbook, that's not the way I work, so no. However, I can recommend what the javascript ninja David Lee recommended, a website called w3schools.com. Just type a question like "javascript data types" into a search engine and it will probably have an entry in the first page somewhwere. Stackoverflow is another useful site, and there are many other websites that have javascript tutorials and references. I tend to just code until I can't remember how to do something, then ask DuckDuckGo (DDG is a good search engine, by the way, that keeps your information private, unlike Google and others. In case you hadn't heard of it). OK, that's it for today, Delta Foxtrot out. BTW, I gave up drinking beer in 1992, but I've been having a craving for a good Gewerztraminer lately, or maybe even a nice Rhein Spätlese or a good crisp Schloss Lieser Mosel–although I have a real spot in my heart for Gewerz. In the '80s I was a buyer for the largest fine wine store in Texas, went to a lot of big auctions, and have even had a reasonable sampling of Eisweins (spelling?) and other late-harvest extravagances in my time. So I would gladly raise a glass of fine German grapejuice in your honor! :) Best regards and yippee-i-o-kayay, my friend! Daniel |
#5 : 29/07-24 09:10 GSComputer
Posts: 36
|
Reply to #4:
Dear Friend; no, that was not "Probably more information than you were looking for, right? :)" That helps me to understand. I'm more hardware orientated (repairing hardware) and want to understand why and how something works. I will use your proposal to find java expressions and other things Begim of privat words: I think we shouldn't bore other users in the forum with private things, but I would like to contact you also discussing private things like loving sweet wines like "Gewürztraminer or Spätlese". Most Americans I know love GERMAN Beer. I prefer dry wines like Chablis or Spanish Redwine like Rioja or Tempranillo. If you so see a possibilty to contact for private conversations let me Know under [email protected] ( this is a temporary Email Adress) END of Private words Have a nice day Gerhard |