FileSystem.RenameFile(String, String) 方法

定義

重新命名檔案。

public:
 static void RenameFile(System::String ^ file, System::String ^ newName);
public static void RenameFile(string file, string newName);
static member RenameFile : string * string -> unit
Public Shared Sub RenameFile (file As String, newName As String)

參數

file
String

檔案將重新命名。

newName
String

檔案名稱換了。

例外狀況

newName 包含路徑資訊,或以反斜線(\)結尾。

fileNothing

-或-

newNameNothing 空字串。

該目錄不存在。

存在一個名稱為 的現存檔案或目錄。newName

路徑超過系統定義的最大長度。

路徑中的檔案或目錄名稱包含冒號(:),或格式無效。

使用者缺乏必要的權限來查看路徑。

使用者無需取得所需的權限。

範例

此範例將檔案 Test.txt 重新命名為 SecondTest.txt

My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")

將「」改C:\Test.txt成你想重新命名的檔案的路徑和檔名。

備註

此方法無法用於移動檔案;使用該 MoveFile 方法來移動並重新命名檔案。

下表列出一個涉及此 My.Computer.FileSystem.RenameFile 方法的任務範例。

看!
重新命名檔案 如何:在 Visual Basic 中重新命名檔案

適用於