Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Working with a date range of files...

Oct
29
0
How can I enumerate and work with an age range of files based in minutes? I'd like to be able to copy files from a directory based on being x minutes old.
 
For a file with name %f, this will give the age in minutes of its WRITE time (to 1 decimal places).

Code:
%@eval[(%@makeage[%_date,%_time] - %@fileage["%f"]) / 600000000=1]

And this will use its CREATION time.

Code:
%@eval[(%@makeage[%_date,%_time] - %@fileage["%f",,c]) / 600000000=1]

For example, using write times,

Code:
v:\> do f in n*.txt (echo %f is %@eval[(%@makeage[%_date,%_time] - %@fileage["%f"]) / 600000000=1] minutes old)
nowfile.txt is 12.1 minutes old
ntqip.txt is 646157.7 minutes old

To TCC, an "age" is a Windows FILETIME ... the number of 100-nanosecond units since 01-01-1601, 00:00:00. Dividing by 10,000,000 gives seconds (and so on).
 
Got it. Thank you for a direction to try. I was hoping for a non looping solution since the file set I have to work with can be several thousand big and I would need to run this quickly when I needed it. Essentially I need to grab log files from multiple servers within x minutes of the current time and dump them into a database to look for failures when problems pop up. I got the database side ready to go I just need to be able to grab the right files when someone does a shoulder tap on me and asked, "Hey, can you look at...."
 
The loop was just for the sake of an example of getting the "minutes_old" of a file. Depending on how much you know about the possible target files you may or may not need a loop. A user-defined function could help with determining "minutes_old". Perhaps something like

Code:
function minutes_old `%@eval[(%@makeage[%_date,%_time] - %@fileage[%1]) / 600000000=1]`

Then you could do something like

Code:
if %@minutes_old[%filename] LT 10 ...
 
Thanks for the code examples. I think I have something working. Still can't see how I can avoid a loop since a custom function would need to be applied to individual files (as far as I can see). But, since the log names incorporate the date in a 2022-05-12 format I can at least target today's date with a file mask on the do statement fileset which reduces the loop to a manageable level for the file age evaluation to further cut it down to the last x minutes of the day.

Thanks again for helping me weed through it.
 
/[d-0] modified today (from today minus zero days, to today)
[t-120,+120] modified between two hours ago and the current time on any date

so could do:

/[d-0] /[t-10]

might give preferred results
 
Well, I just learned something I never knew. In HELP DATERANGES, you'll find this little nugget:

Instead of a date, you can specify a file age for the first and/or second parameter.

So. To get the current time as an age:
Code:
set now=%@makeage[%_isodate,%_time]

And to get five minutes ago as an age:
Code:
set then=%@eval[%@makeage[%_isodate,%_time] - ( 5 * 60 * 10000000 )]

And then you can plug that right into a date range:
Code:
dir /a /[d%then]

A user-defined function to convert n minutes ago to a file age would be trivial.
 
Well, I just learned something I never knew. In HELP DATERANGES, you'll find this little nugget:



So. To get the current time as an age:
Code:
set now=%@makeage[%_isodate,%_time]

And to get five minutes ago as an age:
Code:
set then=%@eval[%@makeage[%_isodate,%_time] - ( 5 * 60 * 10000000 )]

And then you can plug that right into a date range:
Code:
dir /a /[d%then]

A user-defined function to convert n minutes ago to a file age would be trivial.
That's good. I didn't mention ranges because of the problem of time ranges not going back into the previous day. That is, for example, /[t-60] doesn't work as might be desired between 00:00:00 and 00:59:59. Your method gets around that.
 

Similar threads

Back
Top