File.SetCreationTime(String, DateTime) 方法

定義

設定檔案建立的日期和時間。Sets the date and time the file was created.

public:
 static void SetCreationTime(System::String ^ path, DateTime creationTime);
public static void SetCreationTime (string path, DateTime creationTime);
static member SetCreationTime : string * DateTime -> unit
Public Shared Sub SetCreationTime (path As String, creationTime As DateTime)

參數

path
String

要設定其建立日期和時間資訊的檔案。The file for which to set the creation date and time information.

creationTime
DateTime

DateTime,包含要為 path 的建立日期和時間設定的值。A DateTime containing the value to set for the creation date and time of path. 這個值以本地時間表示。This value is expressed in local time.

例外狀況

找不到指定的路徑。The specified path was not found.

path 為零長度字串,只包含空格,或包含一或多個如 InvalidPathChars 所定義的無效字元。path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

pathnullpath is null.

指定的路徑、檔案名稱,或兩者都超出系統定義的長度上限。The specified path, file name, or both exceed the system-defined maximum length.

執行此作業時發生 I/O 錯誤An I/O error occurred while performing the operation.

creationTime 指定的值超出這項作業允許的日期或時間範圍 (或兩者皆超出)。creationTime specifies a value outside the range of dates, times, or both permitted for this operation.

呼叫端沒有必要的權限。The caller does not have the required permission.

path 格式無效。path is in an invalid format.

備註

path允許參數指定相對或絕對路徑資訊。The path parameter is permitted to specify relative or absolute path information. 相對路徑資訊會轉譯為相對於目前工作目錄。Relative path information is interpreted as relative to the current working directory. 若要取得目前的工作目錄,請參閱 GetCurrentDirectoryTo obtain the current working directory, see GetCurrentDirectory.

NTFS 格式的磁片磁碟機可能會在短時間內快取檔元資訊,例如檔案建立時間。NTFS-formatted drives may cache file meta-info, such as file creation time, for a short period of time. 如此一來,如果您要覆寫或取代現有的檔案,則可能需要明確地設定檔案的建立時間。As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

如需一般 i/o 工作的清單,請參閱 一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

適用於

另請參閱