I need to copy a bunch of files, making the directories
as needed. I would like to use the windows api to do this.
Does anyone know a good method to do this?
Printable View
I need to copy a bunch of files, making the directories
as needed. I would like to use the windows api to do this.
Does anyone know a good method to do this?
here's some code that Matthew Gates posted before that might help ya out, you'll obviously have to adapt it to your needs
Code:Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_SILENT = &H4
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_ALLOWUNDO = &H40
Private Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub cmdBackup_Click()
Dim SHF As SHFILEOPSTRUCT
Dim lret As Long
SHF.wFunc = FO_COPY
SHF.hWnd = Me.hWnd
SHF.pFrom = Dir2.Path & "*.*"
SHF.pTo = Dir1.Path
SHF.fFlags = FOF_NOCONFIRMATION
lret = SHFileOperation(SHF)
If lret <> 0 Then
MsgBox "Error Backup aborted..."
Dir1.Refresh
End If
If lret = 0 Then
MsgBox " File Backup Successfull! "
Dir1.Refresh
Dir2.Refresh
End If
End Sub
Thank you for your help but this will not create
subdirectories as necessary :(
It doesn't?
strange...
Try this one then..
Hope this one works wellCode:'FileOperation
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
'FileOperation
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_MOVE = &H1
Private Const FO_RENAME = &H4
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_CONFIRMMOUSE = &H2
Private Const FOF_FILESONLY = &H80
Private Const FOF_MULTIDESTFILES = &H1
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_NOCONFIRMMKDIR = &H200
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_SILENT = &H4
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_WANTMAPPINGHANDLE = &H20
'FileOperation
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
'FileOperation
Public Enum FileOps
fCopy = FO_COPY
fMove = FO_MOVE
fDelete = FO_DELETE
fRename = FO_RENAME
End Enum
'---//// FileOperation \\\\---
Public Sub FileOperation(Src As String, Dest As String, Operation As FileOps, Optional Silent As Boolean = True)
Dim tmp As SHFILEOPSTRUCT, ret&
tmp.pFrom = Src
If Len(Dest) Then tmp.pTo = Dest
tmp.wFunc = Operation
If Silent Then tmp.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
ret = SHFileOperation(tmp)
End Sub
'---//// End FileOperation \\\\---
thx for your help.
woohoo WORKS!!!
thanks again!