GetNewestFile: time resolution question

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
remco.remco
Newbie
Posts: 12
Joined: Wed Jul 06, 2016 12:19 pm

GetNewestFile: time resolution question

Post by remco.remco » Thu Sep 29, 2016 12:29 pm

Hi,

I want to use the command GetNewestFile to get the file that was most recently written to a certain folder.
The files are being written quite often, maybe 20x per second or so.

My question is: when a file is written, what timestamp resolution is used. Seconds? If so, then how to distinguish between multiple files written in the same second. If it uses higher resolution, say milliseconds, that would be perfect for me.

(How would it then handle two files that were written in the same millisecond?)

Kind regards,
Remco

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: GetNewestFile: time resolution question

Post by Marcus Tettmar » Fri Sep 30, 2016 11:14 am

See this:
https://msdn.microsoft.com/en-gb/librar ... s.85).aspx

"A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). The system records file times when applications create, access, and write to files."

It is this filetime that GetNewestFile looks at. So it should be within your desired accuracy. Bottom line is it is as accurate as Windows makes it. We can't make it MORE accurate obviously, as we only get given what Windows gives us.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: GetNewestFile: time resolution question

Post by JRL » Fri Sep 30, 2016 2:03 pm

I'm kind-a wondering what it is you're trying to accomplish.

Files written to a folder at a rate of 20 per second might be a real challenge if you are planning to work with every single file. On average you will only have 50 milliseconds to identify the newest file and perform activity on it. That activity will need to include either a file move or a file delete, either of which could easily take more than 50 milliseconds depending on the computers available resources and the size of the files.

If you are not planning to move or delete every file which using GetNewestFile> implies, then it really won't matter which file is absolutely the newest. As your files accumulate in the folder at a rate of 20 per second your acquisition of the newest file name will get slower and slower because more data simply takes longer to evaluate. Within 10 minutes you'll have 12000 files in your folder and GetNewestFile> will go from working nearly instantaneously to taking about 200 milliseconds to acquire a file name. So while you acquire one file name four more will be created. This doesn't take into account the tasks you perform on each file and how long those tasks take to complete. You will only work with a small percentage of the files and the actual file selected will be "new" but still arbitrary.

remco.remco
Newbie
Posts: 12
Joined: Wed Jul 06, 2016 12:19 pm

Re: GetNewestFile: time resolution question

Post by remco.remco » Sun Oct 02, 2016 9:22 pm

Hi,

Thanks for your answer.

From a virtual machine, I get files in a shared folder. It saves them with max. 20 per second for a short time, then speed decreases. The total number of files in a session will be around 400 or so. So it's not generating files at 20/sec constantly.

In windows 10 I read the files. Not all of them, the newest only. If I get one that is not the newest, but close, that's also fine.
So I check if there is a file present that is newer than what I already read previously. If so, I read it and process it.

I don't delete or move files, for the reasons that you mention.

I now use a different method that seems to work. In the virtual machine, every file that is saved gets a number, 0,1,2,3 et cetera. In windows 10, I count the number of files in the folder. And then I check if there are more files present than at my previous read. If so, I read the file with the highest number

Kind regards,
Remco

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts