PDA

View Full Version : سوال: کپی کردن فایل با API



IamOverlord
چهارشنبه 19 اسفند 1388, 01:31 صبح
سلام دوستان!
یه سوال فوری: چه طوری می شه با CopyFile در kernel32 کار کرد؟ روش تعریف API :

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

خواهش می کنم کمک کنید...

IamOverlord
چهارشنبه 19 اسفند 1388, 02:07 صبح
یاحق
سلام دوستان!
خودم نحوه ی استفاده اش رو فهمیدم :

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)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
'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



با تشکر از همگی!
:چشمک: