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
See Also: MoveFile
Category: Files
Go back to the alphabetical Function listing.
Go back to the Reference section index.
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/copyfile.html