dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Filetimes in FAT and NTFS

  1. #1
    Join Date
    Feb 2008
    Posts
    16

    Filetimes in FAT and NTFS

    I am writing a program that needs to check if the filetimes for two files are equal. I was testing it between files on my local hard drive (NTFS) and a USB flash drive (FAT), and it seems that the file times on the flash drive are rounded strangely. Some files are rounded several seconds up, and it doesn't store any millisecond value. This is all fine, I just can't figure out how they are changed when copied from NTFS to FAT. Once I know that, I'll just convert them both to the same thing before I compare them. Can anyone help me out?

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Filetimes in FAT and NTFS

    Unfortunately because in differnces between the internal storage mechganisms of the file systems, it is impossible to tell for certain if two times are identical or not.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Feb 2008
    Posts
    16

    Re: Filetimes in FAT and NTFS

    Well, the FAT files that I am comparing are copies from the NTFS drive. So if I could recreate the changes that a copied file would go through, I could compare that.

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Filetimes in FAT and NTFS

    Quote Originally Posted by Spasm View Post
    Well, the FAT files that I am comparing are copies from the NTFS drive. So if I could recreate the changes that a copied file would go through, I could compare that.
    Consider....

    1) I have a number (integer) between 100 and 999.
    2) I tell you the first two digits
    3) You tell me the EXACT number that I have.

    You very simply CAN NOT.

    Now to make it a little closer... Two people give you numbers accoring to the same rule...Did they both think of the Same number?

    There is information lost in the transfer.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Feb 2008
    Posts
    16

    Re: Filetimes in FAT and NTFS

    I'm making a program that creates a backup of a folder in real time as files are created/modified/deleted (it's pretty easy to do with a FileSystemWatcher). My function that checks to see if a specific file needs to be copied compares the file size and last write times of the two files, and if they're not equal, it uses File.Copy to make a backup.

    So the two files I'm comparing are copies. If they're on two different kinds of file systems, the file times are probably going to be different, even though the file was copied. If I convert the NTFS file time to what it [i]would]/i] be if the file were copied to a FAT file system, my function would work properly.

    The only strange situation where my function would incorrectly think the files are equal when they're actually different is if this happened: A file is saved on an NTFS drive, and then is saved again on the exact same tick that the NTFS file time would be changed to if it were copied to FAT, but the file has the same size. I doubt that will ever happen to small number of people who are going to use my program, and in fact, I doubt that has ever even happened in the history of computing.

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Filetimes in FAT and NTFS

    Then if you are willing to accept that, I dont see what the problem is, except if the computers are going to be in different time zones.....(or the timezone for a specific computer changes...)
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Feb 2008
    Posts
    16

    Re: Filetimes in FAT and NTFS

    I just don't know how to do that NTFS file time to FAT file time conversion ~_~

    It doesn't just round up to the nearest second, sometimes it rounds up two seconds, sometimes it rounds up just one, I can't figure it out.

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Filetimes in FAT and NTFS

    Quote Originally Posted by Spasm View Post
    I just don't know how to do that NTFS file time to FAT file time conversion ~_~

    It doesn't just round up to the nearest second, sometimes it rounds up two seconds, sometimes it rounds up just one, I can't figure it out.
    Much more lilely you are seeing the results of things being cached across the drives. On busy systems, I have seen timestamps of flash drives that differ by up to a minute from the time I copied the file. Simply the nature of the beast. You would be much bettter of using MD5....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Filetimes in FAT and NTFS

    I would consider keeping an internal record concerning each monitored file. From this record you could tell the last time it was copied, and compare that to it's current LastWriteDate (or whatever you're using)...

    Just a thought...
    It's not a bug, it's a feature!

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)