Solved

Copying Directories With SHFileOperation

Posted on 2004-04-09
1
387 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 240 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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