FileCopy 函式

更新:2007 年 11 月

複製檔案。

My.Computer.FileSystem 物件 在檔案 I/O 作業中的產能和效能勝過 FileCopy。如需詳細資訊,請參閱 My.Computer.FileSystem.CopyFile 方法

Public Sub FileCopy( _
   ByVal Source As String, _
   ByVal Destination As String _
)

參數

  • Source
    必要項。String 運算式,指定要複製的檔案名稱。Source 可能包括原始程式檔 (Source File) 的目錄或資料夾和磁碟。

  • Destination
    必要項。String 運算式,指定目標檔案名稱。Destination 可能包括目標檔案的目錄或資料夾和磁碟。

例外狀況

例外狀況類型

錯誤代碼

條件

ArgumentException

52

Source 或 Destination 為無效值或尚未指定。

IOException

55

檔案已經開啟。

FileNotFoundException

53

檔案不存在。

如果將使用非結構化錯誤處理的 Visual Basic 6.0 應用程式升級,請參閱「錯誤代碼」資料行 (您可以將錯誤代碼與 Number 屬性 (Err 物件) 比對)。但是,請盡可能考慮以 Visual Basic 的結構化例外處理概觀 取代這類錯誤控制項。

備註

如果您嘗試在目前開啟的檔案上執行 FileCopy 函式,將會發生錯誤。

FileCopy 需要完全信任,才能在本機磁碟上運作。

範例

這個範例會使用 FileCopy 函式,將某個檔案複製到另一個檔案。為了這個範例的目的,會假設 SrcFile 是包含某些資料的檔案。

Dim SourceFile, DestinationFile As String
SourceFile = "SRCFILE"   ' Define source file name.
DestinationFile = "DESTFILE"   ' Define target file name.
FileCopy(SourceFile, DestinationFile)   ' Copy source to target.

智慧型裝置開發人員注意事項

不支援這個函式。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**FileSystem

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

工作

HOW TO:在 Visual Basic 中於不同資料夾內建立檔案複本

HOW TO:在 Visual Basic 中於相同目錄內建立檔案複本

HOW TO:在 Visual Basic 中將目錄複製到另一個目錄

參考

Kill 函式

ArgumentException

IOException

FileNotFoundException