Results 1 to 5 of 5

Thread: how to copy folder along with content to another new folder??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Location
    Jakarta,Indonesia
    Posts
    100

    how to copy folder along with content to another new folder??

    hi all,i have a problem here,
    i want to copy folder along with content to another new folder,
    i use this code

    Dim source As String = ""
    Dim destination As String = ""

    source = "C:\Documents and Settings\user\Desktop\weapon"
    destination = "C:\weapon\"

    Try
    If Not Directory.Exists(source) Then
    MsgBox("file yg mo dipindahkan tidak ada")
    Return
    End If
    If Directory.Exists(destination) Then
    MsgBox("file destination sudah ada")
    Return
    End If

    Dim a As DirectoryInfo = New DirectoryInfo(source)
    a.MoveTo(destination)

    Catch ex As Exception
    MsgBox(ex.Message)
    Return
    End Try
    this code make me copy source to destination but also delete source,
    this code delete folder source and move to destination.
    All i want is not delete folder source.

    anyone can help me??

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to copy folder along with content to another new folder??

    My.Computer.FileSystem.CopyDirectory
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Location
    Jakarta,Indonesia
    Posts
    100

    Re: how to copy folder along with content to another new folder??

    hi jmcilhinney

    thx a lot,i have test using little size folder and it works well.
    but with folder with contain 16.363 files and size 35,5 mb it take 1 minute.

    it's ok,although it take a lot time.
    thank you very much!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to copy folder along with content to another new folder??

    Try copying that same folder in Windows Explorer. In theory it should take the exact same time as I believe they use the same functionality.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: how to copy folder along with content to another new folder??

    If you want you can provide a progress UI using that functionality

    Code:
    My.Computer.FileSystem.CopyDirectory(sourceDirectoryName ,destinationDirectoryName ,showUI)
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width