Fun with lexicals
f$delta_time trick
Just a shorty for you. How do you tell in a command procedure if a file was created today? I'm talking about a one-liner, with no temporary files, piping, nor jumping hurdles with f$cvtime...if f$delta_time(f$file("my:file.spec","CDT"),"Tomorrow") .lts. " 1"
...is true, then it was created today. If false, then it was created before today. Note there are 3 blank spaces before the "1" in quotes, and you can change that to any number you want (right-justified in a 4 character field). Want to check if the file was created in the last week? Use " 7". Last 3 weeks? " 21" (two spaces). And so on...
"Tomorrow" translates to midnight, tonight. "CDT" is the Creation Date and Time of the file. The delta time will always be a positive value (unless you've got a file created in the future, which Analyze/Disk/Repair should fix for you!) Using the text string delta time returns, you can actually test to see if a file was created within the past 'delta time', by changing the "Tomorrow" to the null string, "" (i.e., the current time), and change the right side of the comparison to a complete delta time spec (e.g., " 0 12:00:00.00" for within the past 12 hours.)
One final caveat: you'll need OpenVMS v8.x for f$delta_time to understand "Today", "Tomorrow", etc. This was not supported in 7.3 -- you needed to use f$cvtime to convert the relative descriptors to a valid time spec. So there is a circumstance where you'd have to jump the f$cvtime hurdle. I'd say "live with it", but you really should upgrade!
Cool, huh? Well, I think so...
No comments:
No trackbacks: