Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Platforms: Win 32s, Win 95/98, Win NT
CopyFile copies a file from one location to another, just like copying a file in Windows Explorer or in some other way. Depending on the value for bFailIfExists, it will either overwrite the target file if it already exists, or will fail. The function retuns 1 if successful, or 0 if an error occured.
Example:
' Copy the file C:\MyStuff\temp.txt to C:\Junk\buffer.txt.
' Do not overwrite C:\Junk\buffer.txt if it already exists.
Dim retval As Long ' return value
' copy the file
retval = CopyFile("C:\MyStuff\temp.txt", "C:\Junk\buffer.txt", 1)
If retval = 0 Then ' failure
Debug.Print "Copy failed -- C:\Junk\buffer.txt already exists.
Else ' success
Debug.Print "Copy succeeded."
End If
Related Call: MoveFile
Category: Files
Back to the index.