FileSystemInfo.CreationTime 属性

定义

获取或设置当前文件或目录的创建时间。

public:
 property DateTime CreationTime { DateTime get(); void set(DateTime value); };
public DateTime CreationTime { get; set; }
member this.CreationTime : DateTime with get, set
Public Property CreationTime As DateTime

属性值

当前 FileSystemInfo 对象的创建日期和时间。

例外

Refresh() 不能初始化数据。

指定的路径无效:例如,它位于未映射的驱动器上。

当前操作系统不是 Windows NT 或更高版本。

调用方试图设置无效的创建时间。

示例

以下示例演示 属性 CreationTime 。 此代码示例是为 FileSystemInfo 类提供的一个更大示例的一部分。

static void DisplayFileSystemInfoAttributes(FileSystemInfo^ fsi)
{
    //  Assume that this entry is a file.
    String^ entryType = "File";

    // Determine if entry is really a directory
    if ((fsi->Attributes & FileAttributes::Directory) == FileAttributes::Directory)
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console::WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi->FullName, fsi->CreationTime);
}
static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
{
    //  Assume that this entry is a file.
    string entryType = "File";

    // Determine if entry is really a directory
    if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
}
Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo)
    ' Assume that this entry is a file.
    Dim entryType As String = "File"

    ' Determine if this entry is really a directory.
    If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
        entryType = "Directory"
    End If

    ' Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", _
        entryType, fsi.FullName, fsi.CreationTime)
End Sub

注解

注意

此方法可能返回不准确的值,因为它使用本机函数,其值可能不会由操作系统持续更新。

如果对象的当前实例FileSystemInfo是从以下DirectoryInfo任一方法返回的,则属性的值CreationTime是预先缓存的:

若要获取最新值,请 Refresh 调用 方法。

如果 对象中描述的 FileSystemInfo 文件不存在,此属性返回 1601 年 1 月 1 日午夜 12:00,00, (C.E.) 协调世界时 (UTC) ,调整为本地时间。

在不支持创建或诞生时间的 Unix 平台上,此属性返回上次状态更改的时间和上次修改的时间。 在其他平台上,它返回 1601 年 1 月 1 日午夜 12:00, (C.E.) 协调世界时 (UTC) ,调整为本地时间。

NTFS 格式的驱动器可能会缓存文件元数据信息(例如文件创建时间)很短的时间。 此过程称为文件隧道。 因此,如果要覆盖或替换现有文件,可能需要显式设置文件的创建时间。

适用于

另请参阅