Or, if you are copying to a location where the file aready exists, (using name here will raise an error), you can use:
VB Code:
'========================================== 'for the value, bFailIfExists. If you set this value to true, then 'the file won't be copied is the file already exists. If this value 'is false, then the file will overwrite any existing copies of the 'file '=========================================== Private Declare Function CopyFile Lib "kernel32" Alias _ "CopyFileA" (ByVal lpExistingFileName As String, _ ByVal lpNewFileName As String, _ ByVal bFailIfExists As Long) As Long Private Command1_Click() Dim lret as long '=========================================== 'This will create a duplicate file, without deleting the original 'file. And will overwrite the destination file, if it already exits. '=========================================== lret=CopyFile("c:\windows\desktop\test.txt", "c:\windows\desktop\test1.txt", True) End sub
Hope this helps.




Reply With Quote