The legal tricks-Learn Your Self

Latest gadgets,softwares,hardware,reviews,programming and campuses, game cheats ext......

Copy Files Using the Win32 API

Version Compatibility: Visual Basic 5, Visual Basic 6

More information: In my testing, there was a bit of a speed difference when copying large files using the FileCopy API function, as compared to built-in VB methods such as the FileCopy method or the FileSystemObject.

Instructions: Copy the declarations and code below and paste directly into your VB project

Option Explicit

Private Declare Function CopyFile Lib "kernel32" _
Alias "CopyFileA" (ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, ByVal bFailIfExists As Long) _
As Long

Public Function APIFileCopy(src As String, dest As String, _
Optional FailIfDestExists As Boolean) As Boolean

'PURPOSE: COPY FILES
'PARAMETERS: src: Source File (FullPath)
'dest: Destination File (FullPath)
'FailIfDestExists (Optional):
'Set to true if you don't want to
'overwrite the destination file if
'it exists

'Returns (True if Successful, false otherwise)

'EXAMPLE:
'dim bSuccess as boolean
'bSuccess = APIFileCopy ("C:\MyFile.txt", "D:\MyFile.txt")

Dim lRet As Long
lRet = CopyFile(src, dest, FailIfDestExists)
APIFileCopy = (lRet > 0)

End Function

0 comments: