read file from directory every minute

read a file located at the specific directory every minute, if file is not updated for more than a minute, return FALSE.
means i need to check status of the file is updated or not in every minute.

I need code ..it's urgent ..
Last edited on
I need code ..it's urgent ..

what have you done so far?
actually want to make a small app in visual c++ for read file in every minutes
from any directory.
directory have a file which is update in every minute .so i want to check status
of that file.
you haven't answered my question.
nothing just searching in website but i not get ..
google: "c++ get last modified time file"
ya thanks...
Hello,

if I may for each timer cycle ; I would checksum the file and retain the signature ; then when the next cycle happens:

if file_checksum != last_checksum :
____I need to do something, last_checksum = file_checksum;
else:
____do nothing

Material:

1- you need a periodic timer ; an interesting discussion here : http://codereview.stackexchange.com/questions/40473/portable-periodic-one-shot-timer-implementation

else win32 API:
https://msdn.microsoft.com/en-us/library/ms686289(v=vs.85).aspx

2- you need a sha(n) hash impl
http://www.cryptopp.com might be your friend

advice: usually ; when checksumming a file ; I read per chunk/ (aligned blocks) (calculated according to the size of the file, bigger the file, bigger the block) then I update the hash context with each chunk until EOF ; it avoids you to put all the file content into memory ; downside: the reading part is a bit slower ; but the runtime part is safe.

an option/optimization in your program ; you could read the file from the end and keep an array of checksummed pre-sized blocks let say 1024, instead of a global signature ; then comparing while reading: if one of the block signature [last read] differs, no need to go further the file did change, sure you need to manage your block list as the length can change et cetera and create some rules ; don't know ; just a thought.

One day, I had implemented a fast checksum which was checking only few blocks in the beginning, in the middle, and in the end, (keeping the offsets, if the size was shrunk, you would know immediately) never got any collision on million files.

Other question: why every minute and not having a file-system watcher?

https://msdn.microsoft.com/en-us/library/aa365465(VS.85).aspx



Last edited on
Topic archived. No new replies allowed.