CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    San Diego, California
    Posts
    49

    file date/time stamp

    Hello,

    I have a program that needs to compare the current date and time against a file. The file I'm comparing against is a file that gets written to regularly by an external program and is always open.

    I was using the file system object to accomplish this:

    Set f1 = fso.GetFile(sitePath)
    timedif = DateDiff("n", f1.DateLastModified, curdatetime)

    My question is: Is there a better way to do this? I'm suspicious that the timedif function is not returning the correct results. It seems to me that although the file is getting written to, the f1.DateLastModified value is incorrect and older than it should be. This file is always open and being written to like I mentioned before.

    Any suggestions on how I can more accurately accomplish this?

    Thanks,
    Steph!

  2. #2
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: file date/time stamp

    Not sure exactly what you are trying to do, but if you need to syncronize with another application's file accesses this probably isn't the best way to do it. This is what MSDN has to say about it, and I'm guessing that your problem is symptomatic of something like this:
    Quote Originally Posted by MSDN
    Not all file systems can record creation and last access times, and not all file systems record them in the same manner. For example, the resolution of create time on FAT is 10 milliseconds, while write time has a resolution of 2 seconds and access time has a resolution of 1 day, so it is really the access date. The NTFS file system delays updates to the last access time for a file by up to 1 hour after the last access.
    Also, on NTFS or other journaling file systems, the access time wouldn't be written until the filesystem cache was flushed, so other methods of detecting file changes (such as FindFirstChangeNotification) would also be subject to the same problems.

    What are you trying to accomplish? If the external program writes infrequently, FindFirstChangeNotification might be the way to go. If it writes a lot, you might be able to hook it's file accesses.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured