I am trying to automate the task - looking for files in a folder daily. There are 14 files with different names. Example: ACH_ACC_20210607.csv, PRP_ACC_20210607.csv, ACR_PREM_20210607.csv etc. My activity is to check daily if above 14 files are present or not in a folder.
The date in the filename for all the files will be current date minus 1 i.e. yesterday date. When we are checking on monday, we will check for friday so minus 3 days.
Can anyone help me to automate this activity? below is the code which works for only one file. But i am having difficulty writing code to check multiple files.
I wouldn't loop over the files that are there (which is what the code does now), I would loop over the files that should be there. So you need an array of all the filename prefixes you want to check, and then loop through them, constructing the full filename from the prefix and check whether it's present.
You mentioned what you wanted to do on Monday, to get Friday as a yesterday, however, why are you having that second line of code and calling it every single day? As if it would get you Friday every time - it won't.
What you want to do, is to figure out whether today is Monday or not, and then as for a Friday to subtract 3 days. Check documentation what methods LocalDate has, I'm sure there is something useful.
My only complaint with that approach is that the trinary operator is considered to be somewhat dangerous.
The example I gave is an anti-bugging approach in that the day will at worst be in the ballpark with no danger of it slipping through uninitialized (technically, that SHOULDN'T happen for the trinary either, but like I said, it's not universally loved).
The one downside is that it's subtracting calendar days, which might possibly be more overhead than an equivalent case where the affected variable was a simple integer or float. Then again, premature optimization is the worst kind of operation.
Loudly announcing something is true and finding out you're wrong makes you feel foolish.
Finding out you're wrong and refusing to admit it makes you LOOK foolish.
What's wrong with the ?: operator? Its behaviour is strictly defined. I would suggest both expressions after ? be the same type, because it seems to cast types silently if they aren't exactly the same. It also often has to be wrapped in (...) if it is every used in conjunction with other operators because of its low precedence. It is possible to nest ?:s, but it takes some getting used to its right‑associativity.