|
-
Jun 1st, 2006, 03:35 AM
#3
Thread Starter
New Member
Re: [2005] API File operations error with multiple folders to copy
Thanks for your quick reply and friendly welcome greeting!
I used: My.Computer.FileSystem.CopyDirectory(strSource.Item(intI), strDest, True), in stead since I want to copy directories what i already tested before...
This only copies the contents of the folders and does it 'hidden' , no process dialog.
It solves the error I had since this method copies several folders (though it doesn't create the root folder in the destination which is also needed) but I really need the progress to be visible
This is the class I'm using:
Public Class FileCopy
#Region "API Declaration"
'Enum for holding Constants
Private Enum FO_Func As Short
' Operations available
FO_COPY = &H2 ' Copy File/Folder
FO_DELETE = &H3 ' Delete File/Folder
FO_MOVE = &H1 ' Move File/Folder
FO_RENAME = &H4 ' Rename File/Folder
' Flags available
FOF_ALLOWUNDO = &H40 ' Allow to undo rename, delete ie sends to recycle bin
FOF_NOCONFIRMATION = &H10 ' No File Delete or Overwrite Confirmation Dialog
FOF_FILESONLY = &H80 ' Only allow files
FOF_SILENT = &H4 ' No copy/move dialog
FOF_SIMPLEPROGRESS = &H100 ' Does not display file names
End Enum
'Structure that will be used to pass values to the SHFileOPeration API
Private Structure SHFILEOPSTRUCT
Dim hwnd As Integer
Dim wFunc As Integer
Dim pFrom As String
Dim pTo As String
Dim fFlags As Short
Dim fAnyOperationsAborted As Boolean
Dim hNameMappings As Integer
Dim lpszProgressTitle As String
End Structure
'Declaration of the API
Private Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
#End Region
'Copy Files function used to copy files from Source to Target
'Param1 : sSource --> The source file or Folder
'Param2 : sSource --> The target file or Folder
Public Shared Function CopyFiles(ByVal sSource As String, ByVal sTarget As String) As Boolean
Dim _ShFile As SHFILEOPSTRUCT
Try
_ShFile.wFunc = &H2 ' = FO_Func.FO_COPY
_ShFile.fFlags = FO_Func.FOF_ALLOWUNDO
_ShFile.pFrom = sSource
_ShFile.pTo = sTarget
SHFileOperation(_ShFile)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
Return True
End Function
End Class
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
|