Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i want to copy a folder inclusive all subfolders and all files to a specified location. How do i do that? I dont want to code this myself if there is a possibility to use an existing component.

 

The best way for me would be to use the copy-dialog which the windows-explorer use because there is everything handled. all exceptions, etc. is there a way i can use this? thanks!

sometimes I blog...

http://michal.grafix.at

  • Leaders
Posted

if you want to move an entire directory without a loop , you can use the filesystemobject class.

here's a quick example ...

       Dim tpFolder As Type = Type.GetTypeFromProgID("Scripting.FileSystemObject")

       Dim objFolder As Object = Activator.CreateInstance(tpFolder)

       Dim objArgs As Object() = {"C:\testing", "F:\testing", True} '/// C:\ existing path , F:\ path to copy to , overwrite if exists on F:\ already

       tpFolder.InvokeMember("CopyFolder", Reflection.BindingFlags.InvokeMethod, Nothing, objFolder, objArgs)

       objFolder = Nothing

Posted

thanks for it but i think its not the right solution for me because i need the explorers copy-dialog. i also want to execute the explorers copy-function ...

so i think i need to use the windows api .. can anyone help?

sometimes I blog...

http://michal.grafix.at

  • Leaders
Posted

if you want to use the api way , here's a quick example i put together ( NOTE : if you want a silent copy , ie: NO progress dialog add FOF_SILENT for the fFlags of the structure ) ...

   Public Structure SHFILEOPSTRUCT
       Public hWnd As Integer
       Public wFunc As Integer
       Public pFrom As String
       Public pTo As String
       Public fFlags As Integer
       Public fAborted As Integer
       Public hNameMaps As Integer
       Public sProgress As String
   End Structure

   Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

   Private Const FO_COPY As Int32 = &H2
   Private Const FO_DELETE As Int32 = &H3
   Private Const FO_MOVE As Int32 = &H1
   Private Const FOF_SILENT As Int32 = &H4 '/// this will hide the progress box ( do NOT use if you wish to see progress )

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim shStructure As New SHFILEOPSTRUCT()
       Dim currentpath As String = "C:\testing" '/// folder to copy
       Dim newpath As String = "F:\testing" '/// new path

       With shStructure
           .wFunc = FO_COPY
           .pFrom = currentpath
           .pTo = newpath
       End With

       SHFileOperation(shStructure)

   End Sub

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...