index > Visual C# General > FileInfo.LastWriteTime issue: does not correctly evaluate

FileInfo.LastWriteTime issue: does not correctly evaluate

Hello All,

I'm currently having an issue when evaluating FileInfo.LastWriteTime between two files.  Basically, the two files in question have the IDENTICAL LastWriteTime values, however the following code evaluates to false:

FileInfo f1 = new FileInfo("C:\\FileTest2\\IUS_GEN.MNV");

FileInfo f2 = new FileInfo("C:\\FileTest2\\SubFolder\\IUS_GEN.MNV");

f1.LastWriteTime == f2.LastWriteTime //this evaluates to false

Strange thing is, if I convert LastWriteTime to string, it evaluates correctly, as in:

f1.LastWriteTime.ToString() == f2.LastWriteTime.ToString() //this evaluates to true!

Both files have the LastWriteTime.ToString() value of 9/01/2006 8:25:47 AM

What's going on?  It seems to evaluate correctly as the native DateTime type for some files, but not all.  Is precision lost when converting to string?

Cheers

Rob

Robert Varga

>  Is precision lost when converting to string?

The string you are generating has the time to the nearest second: DateTime is more accurate so yes, precision is lost.

To understand what's happening, you could try formatting with fractions of seconds (e.g. LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff").

 

JocularJoe
Thanks Joe, I'll have a look at that.
Robert Varga
reply 3

You can use google to search for other answers

 

More Articles

• Help! How to write 'get''set' property for an array of structs?
• Listbox and UserControl
• Reading an XML File, Changing some values
• Label Properties
• MFC Control on c# WinForm
• system.io.filenotfoundexception problem
• create procedure
• How to add SQL ConnectionString editor form.
• Changing CheckBox Checked
• Interop in reverse
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• ASP usercontrol with C#
• Determining Class Dependencies
• Possible to write Outlook Today Plug-In?
• Preventing decompilation!!
• Newbie: Need to combine several .dll int
• DrawUserPrimitives with C# 2.0 and MDX 2
• How to Change the Security settings of I
• Listbox ??
• Place holder
• How to add and use an old DLL library in
• MailMessage + Attachment Question =P
• read INI file from c#
• get user directory
• need help for developing an application
• Webbrowser Help needed

Hot Articles

• Viewing type *.tlb file
• Tow Language
• "æ" and "?" --- Wha
• How To: get all the buttons from a form
• scrollbar in panel
• Regarding WebBrowser Control
• How can I rename remote local user using
• (CreateObject)VB -> C#
• Code Security
• Design Question
• events and childwindows
• cstr() in C#
• WYSIWYG HTML Editor
• Abort a Thread
• Viewing .tga Images

Recommend Articles

• write data to file, data lost..
• Closing a form before opening another
• How to set the timeout for a particular
• How to Show Code Line Numbering in the E
• how to load and retrive an Image from Re
• Playing sounds simultaneously
• Excel Cell data validation
• c# Insert Text into Textbox
• Calling delphi dll with chara parameters
• Changing the Browsable attribute dynamic
• handling events from EventControl by Form
• Dynamic Tables
• .net Windows Service crash
• Logger in multi-threaded application
• Making a settable time delay in C#