Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 19th Aug 2011 10:34
Im making a program that needs to know when a file is not being written to or read from
The way im doing it currently is checking file sizes until the file size stays the same for 100 loops

Any better ways?

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Aug 2011 11:32
Probably the easiest way is by the files modify date. If the files modify date is way off then it's safe to say the file isn't be written right now. If it's the same date and close to the same time then it's probably being written at the moment.

Alfa X made a .dll with one command to get the modified date from a file. It's got a different format than we're used to but that's easily fixed (it's DAY-MONTH-YEAR TIME).

http://forum.thegamecreators.com/?m=forum_view&t=170123&b=1

Download the file and put it in your Darkbasic Pro directory under Compiler/Plugins-User to use it.

SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 19th Aug 2011 12:37
Well that would work great exept my program has to be accurate to the second, date will not work for that :/

Max P
16
Years of Service
User Offline
Joined: 23rd Jan 2010
Location:
Posted: 19th Aug 2011 16:02
You can do this with the matrix1 utility using:

haven't tested it but I guess it will return a 0 if the file is already opened.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Aug 2011 17:22 Edited at: 19th Aug 2011 17:31
Quote: "Well that would work great exept my program has to be accurate to the second, date will not work for that :/"


What is this for exactly? I assumed this was for files that Windows is writing and not directly under your control. If it has to do with files your reading/writing in your own program using FILE OPEN() will work fine. I mentioned the date as the first check so if the file was modified a month ago it shouldn't be given a closer look to see what time it was modified. If you look at that command by Alfa X it shows the time in HOURS:MINUTES:SECONDS so you're accuracy is there if you really need it.

SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 19th Aug 2011 19:29
You assume correctly, But I am not sure if the date modified will work even if it has seconds because it is most likely not updated until the file IO stream is done. I need something to detect when the stream has ended, I do not have the starting date created.

Basicly my program waits until a file is done with IO then moves it, if you move it before IO is done then there is data loss

The filesize method works fine for this but is there a better way?
I will have a look at that dll though

Bluespark
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 19th Aug 2011 22:50
You need to use

and then you can move the file without worrying about data loss.
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 19th Aug 2011 23:00
Im not in control of the file eg. Have not loaded it

Login to post a reply

Server time is: 2026-07-10 22:37:31
Your offset time is: 2026-07-10 22:37:31