| 1. |
Solve : Display a the date & time when a file was last accessed? |
|
Answer» I need to display the date and time when a file was last accessed (not modified). I found several entries in this forum but I was not able to use any of them successfully. I was trying not to use an external program.LOOK at the help for the DIR command. You should see what you are looking for.You can parse the output of dir /b /ta [filename] using FOR /F and use the ~t delimiter to (in theory) get the last-accessed time like this... I tried what was suggested with the dir parameter, but in XP I get back a date that does not match any of the dates (creation, modified, accessed) displayed in the file properties. Isthere any other mean to get to it? Does it differ by much, or is it wildly off? However I think chasing access information is a waste of time. A quick Google told me that Dropbox will only sync the files in your Dropbox folder, which leads me to imagine that the Dropbox local client that is run on a user's machine must keep some kind of record of its own (e.g. changed hash*) to use when deciding that a file needs to be synced. It cannot reliably use filesystem last-access time, as a little thought would soon tell you. I already told you above that for FAT it only has a resolution of 24 hours (MULTIPLE access time changes on the same day are ignored) and in NTFS it can be WRONG for up to 1 hour after the access takes place and also in XP may be disabled by the user and is disabled by default on modern Windows. Finally and conclusively, a changed last access time is not a definite indication that a file has changed in any way. Maybe a change in the last write time might be, but not always. If you insist on chasing file time stamps*, to see the last write time for a file use dir /b /TW instead of dir /b /TA in the one liner I posted above. * I was right. I Googled "Dropbox file change DETECTION" (hint: had you thought of doing this?) and found that Dropbox splits each file into 4 MB blocks and creates a hash on each block. That way, if you change a contiguous 2MB of a 100MB file, it will likely only need to upload 4MB (or 8MB if you cross into a second 4MB block) to re-sync the file, thus saving bandwidth. To find out about file hashing, Google is your friend, but I would imagine that in order to duplicate the functionality of the Dropbox client in this regard you will have to learn some fancy programming tricks.Quote from: ventodibolina on May 12, 2012, 11:48:33 AM deleted comment uh huh... I understand your remarks, however I think I get what I need by using the DIR command which I found to partially work wit htis syntax: for /f "tokens=1" %%G in ('dir /TA "C:\filename.txt"') DO set attributes=%%G However by doing echo %attributes% I get only the last of 5 lines. How can I get the 3rd line which contains the access date? Quote from: ventodibolina on May 12, 2012, 11:40:36 AM Actually I need to check the same parameter that dropbox uses to decide if it must sync a file or not. I assume is the access parameter, because I have a Truecrypt file that even if opened does not show any change in the "modified" date/time field but it does for the "access" date/time.I have never used TrueCrypt but I am wondering if every time you open and close your TrueCrypt file does it reset the Archive attribute regardless of any files being changed inside the TrueCrypt file. And if this is true, does Dropbox look at the Archive attribute to sync?Quote from: ventodibolina on May 12, 2012, 06:07:00 PM I understand your remarks, however I think I get what I need by using the DIR command which I found to partially work wit htis syntax:Code: [Select]for /f "tokens=1" %%G in ('dir /TA "C:\filename.txt" ^| find "filename.txt"') DO set attributes=%%GSurely if Dropbox rehashes file blocks periodically to check if the local copy has changed from the one in the cloud, then the local file is being accessed and the access time will change, even if nothing has changed and no syncing needs to be done? This may not be possible in this instance, but...... When I worked for the county, I had to almost beat those old gals with a club to get them to do their daily and weekly data backups. So to put some teeth in it, I set it up to run the backup program from a batch file, and in the same batch file was a routine to read the date and time from the real time clock and add that info line to the end of a text file. Then all the supervisor had to do was read that text file with a HOT KEY combo, to get a detailed list of exactly when that backup program was run. That text file would continue to live till it was deleted, by the supervisor. It was a little devious, but it got the job done. Eh? |
|