Home › Forums › C Programming › How can we know whether a file is read or not › Re: Re: How can we know whether a file is read or not
February 23, 2010 at 7:23 am
#3611
Chandra3993
Participant
Straight way you can not check the file is read or not.
For specific number of days or epoch seconds you can check
Here I have written the program for checking file is read in last 2 days
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <br /> #include <br /> #include <br /> #include <br /> #include<br /> #include<br /> <br /> main()<br /> {<br /> struct stat but ;<br /> // Here you need to give the file name with absolute path.<br /> stat("/home/pavunkumar/secrect",&but );<br /> // Here I have calculated the one day epoch time.<br /> int limit = 24*60*60;<br /> // Getting the last read time of the file.<br /> int read = but.st_atime ;<br /> int current ;<br /> // Getting the current epoch time.<br /> current=time ( NULL ) ;<br /> // Check file is not open for 2 days.<br /> if (((current-read)/limit) >= 2 )<br /> {<br /> printf ( "file is not read ");<br /> }<br /> else<br /> {<br /> printf ( "file is read " ) ;<br /> }<br /> }<br /> <br /> |