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

注釈

Note

このメソッドは、オペレーティング システムによって値が継続的に更新されない可能性があるネイティブ関数を使用するため、不正確な値を返す可能性があります。

オブジェクトの現在のCreationTimeインスタンスが次DirectoryInfoのいずれかのメソッドから返された場合、FileSystemInfoプロパティの値は事前にキャッシュされます。

最新の値を取得するには、 メソッドを Refresh 呼び出します。

オブジェクトに FileSystemInfo 記述されているファイルが存在しない場合、このプロパティは 1601 年 1 月 1 日午前 0 時 00 分 (C.E.) を返します。協定世界時 (UTC) で、現地時刻に調整されます。

作成または誕生日をサポートしていない Unix プラットフォームでは、このプロパティは、前回の状態変更時刻と最終変更時刻を返します。 他のプラットフォームでは、1601 年 1 月 1 日午前 0 時 00 分 (C.E.) を返します協定世界時 (UTC) で、現地時刻に調整されます。

NTFS 形式のドライブでは、ファイルの作成時間などのファイル メタ情報が短期間キャッシュされる場合があります。 このプロセスは、ファイル トンネリングと呼ばれます。 その結果、既存のファイルを上書きまたは置き換える場合は、ファイルの作成時刻を明示的に設定することが必要になる場合があります。

適用対象

こちらもご覧ください