peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

File.GetLastWriteTimeUtc is inconsistent with Directory.GetLastWriteTimeUtc and other date methods #22

Closed thomaslevesque closed 9 years ago

thomaslevesque commented 9 years ago

All these methods and properties throw an exception e.g. if the file is not found:

File.GetCreationTime[Utc]
File.GetLastAccessTime[Utc]
Directory.GetCreationTime[Utc]
Directory.GetLastAccessTime[Utc]
Directory.GetLastWriteTime[Utc]
FileSystemInfo.CreationTime[Utc]
FileSystemInfo.LastAccessTime[Utc]
FileSystemInfo.LastWriteTime[Utc]

But File.GetLastWriteTime[Utc] does not; it catches all exceptions and returns a default date (DateTime.FromFileTimeUtc(0L)). This is inconsistent.

thomaslevesque commented 9 years ago

Just checked the behavior of System.IO: none of these methods and properties throw an exception.

The behavior in LongPath makes more sense IMO, but it should be made consistent.

thomaslevesque commented 9 years ago

I just noticed two unit tests that specifically check that GetLastWriteTime does not throw on a file that doesn't exist:

These tests should probably be removed...