dotnet / dotnet/dotnet-api-docs
Detecting that a file is not found or has no appropriate date information
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
# Detecting that a file is not found or has no appropriate date information
# General
The following methods all return 12:00:00.00000 January 1, 1601 as the date if the file represented by a **FileSystemInfo** object does not exit or if the operating system cannot supply the requested information:
- FileSystemInfo.CreationTime
- FileSystemInfo.CreationTimeUtc
- FileSystemInfo.LastWriteTime
- FileSystemInfo.LastWriteTimeUtc
In PR #4453, @BillWagner raised the question of how to detect this missing/incomplete information -- whether there's a constant available, or whether the returned date should be compared with some date. Since the .NET Framework does not include a predefined constant for this purpose, detection requires comparison with a specific date. The best alternative is probably to implement a utility method that converts the returned date back to UTC and tests whether the result is less than or equal to 12:00:00.00000 January 1, 1601. It's also possible to avoid the UTC conversion and simply pick some arbitrary date after that, since presumably no file should legitimately have a creation/last write time in the seventeenth century.
//cc @BillWagner @JeremyKuhne
Contributor guide
Assessment
This issue has not been assessed yet.