?
Solved

Copying Directories With SHFileOperation

Posted on 2004-04-09
1
Medium Priority
?
388 Views
Last Modified: 2010-08-05
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
Comment
Question by:belikemike121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 960 total points
ID: 10794151
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question