Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thomaslevesque opened this issue Apr 14, 2015 · 2 comments

Comments

@thomaslevesque
Copy link
Contributor

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
Copy link
Contributor Author

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.

peteraritchie added a commit that referenced this issue Apr 20, 2015
Do not catch exception in File.GetLastWriteTimeUtc (fix #22)
@thomaslevesque
Copy link
Contributor Author

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

  • FileTests.TestGetLastWriteTimeOnMissingFileHasNoException
  • UncFileTests.TestGetLastWriteTimeOnMissingFileHasNoException

These tests should probably be removed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant