|
-
Jan 12th, 2001, 02:41 PM
#1
Thread Starter
Hyperactive Member
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?
Bababooey
Tatatoothy
Mamamonkey
-
Jan 12th, 2001, 02:54 PM
#2
Hyperactive Member
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
VB6.0 SP4
Windows 2000
I'm thinking of a number between
-
Jan 12th, 2001, 03:10 PM
#3
Thread Starter
Hyperactive Member
Thank you for your help but this will not create
subdirectories as necessary 
Bababooey
Tatatoothy
Mamamonkey
-
Jan 13th, 2001, 08:06 AM
#4
Frenzied Member
It doesn't?
strange...
Try this one then..
Code:
'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 \\\\---
Hope this one works well
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 16th, 2001, 07:08 AM
#5
Thread Starter
Hyperactive Member
Bababooey
Tatatoothy
Mamamonkey
-
Jan 16th, 2001, 08:27 AM
#6
Thread Starter
Hyperactive Member
woohoo WORKS!!!
thanks again!
Bababooey
Tatatoothy
Mamamonkey
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|