• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Copying Directories With SHFileOperation

hey, I am currently copying directories (including subdirectories) with the SHFileOperation api call.  It won't work if the Source directory ends with a "\" so naturally i just take out the "\" and it works perfectly.  The problem I am having is copying roots.  If you select like "C:\" it won't work.  I need to know how to copy roots such as "C:\" or "D:\", any help would be greatly appreciated.  If you need my code to be posted say so and I will post it.  Thanx guys.
~Mike
0
belikemike121
Asked:
belikemike121
1 Solution
 
vinnyd79Commented:
Try adding an *

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FO_MOVE = &H1
Const FO_RENAME = &H4
Const FOF_ALLOWUNDO = &H40
Const FOF_SILENT = &H4
Const FOF_NOCONFIRMATION = &H10
Const FOF_RENAMEONCOLLISION = &H8
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_FILESONLY = &H80

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 Sub Command1_Click()
Dim result As Long, fileop As SHFILEOPSTRUCT
With fileop
     .hwnd = Me.hwnd
     .wFunc = FO_COPY
     .pFrom = "E:\*" & vbNullChar & vbNullChar
     .pTo = "D:\SomeFolder\" & vbNullChar & vbNullChar
     .fFlags = FOF_NOCONFIRMMKDIR
End With
result = SHFileOperation(fileop)
If result <> 0 Then
     ' Operation failed
     MsgBox Err.LastDllError
End If
End Sub
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now