Skip to content

Detecting that a file is not found or has no appropriate date information #1415

Open
@rpetrusha

Description

@rpetrusha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri2Indicates issues/PRs that are medium priorityPri3Indicates issues/PRs that are low priorityarea-System.IO

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions