locked
copy folder to another path RRS feed

  • Question

  • I want to transfer a folder of all files to another location using the FolderBrowserDialog1 for 2 path
    Friday, February 16, 2018 8:20 PM

Answers

  • Hi

    Sorry, I don't understand.

    You can move or copy files from any (unprotected) folder to any other folder of your choice. When the second folder browser dialog opens, you can use the create button to make the folder name you want.


    Regards Les, Livingston, Scotland

    • Marked as answer by monemas Friday, February 16, 2018 11:15 PM
    Friday, February 16, 2018 10:44 PM

All replies

  • Hi

    Please post the code you have so far.


    Regards Les, Livingston, Scotland

    Friday, February 16, 2018 8:47 PM
  • I want to transfer a folder of all files to another location using the FolderBrowserDialog1 for 2 path

    https://msdn.microsoft.com/en-us/library/system.io.directory.move(v=vs.110).aspx

    You should indicate the exact problem you are having implementing the example for that method.

    Friday, February 16, 2018 8:55 PM
  • Hi

    Here is some simple code to do it. It Copies the files in SourcePath to DestPath, but DOES NOT delete the originals. If you want, after testing, to do a Move rather than a Copy then uncomment the line

    ' IO.File.Move(sf, df)

    and remove the IO.File.Copy line.

    ' This is one way to copy files
    ' it has NO ERROR CHECKING
    ' for example, protected files will
    ' cause exceptions to occur.
    
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim SourcePath, DestPath As String
        Dim fb As New FolderBrowserDialog
        fb.ShowNewFolderButton = False
        If fb.ShowDialog = DialogResult.OK Then
          SourcePath = fb.SelectedPath
          fb.ShowNewFolderButton = True
          If fb.ShowDialog = DialogResult.OK Then
            DestPath = fb.SelectedPath
            CopyFiles(SourcePath, DestPath)
          End If
        End If
      End Sub
      Sub CopyFiles(s As String, d As String)
        For Each f As String In IO.Directory.GetFiles(s)
          Dim sf As String = IO.Path.Combine(s, IO.Path.GetFileName(f))
          Dim df As String = IO.Path.Combine(d, IO.Path.GetFileName(f))
          IO.File.Copy(sf, df)
          ' IO.File.Move(sf, df)
        Next
      End Sub
    End Class



    Regards Les, Livingston, Scotland



    • Edited by leshay Friday, February 16, 2018 9:26 PM
    Friday, February 16, 2018 9:23 PM
  • Hi

    Here is some simple code to do it. It Copies the files in SourcePath to DestPath, but DOES NOT delete the originals. If you want, after testing, to do a Move rather than a Copy then uncomment the line

    ' IO.File.Move(sf, df)

    and remove the IO.File.Copy line.

    ' This is one way to copy files
    ' it has NO ERROR CHECKING
    ' for example, protected files will
    ' cause exceptions to occur.
    
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim SourcePath, DestPath As String
        Dim fb As New FolderBrowserDialog
        fb.ShowNewFolderButton = False
        If fb.ShowDialog = DialogResult.OK Then
          SourcePath = fb.SelectedPath
          fb.ShowNewFolderButton = True
          If fb.ShowDialog = DialogResult.OK Then
            DestPath = fb.SelectedPath
            CopyFiles(SourcePath, DestPath)
          End If
        End If
      End Sub
      Sub CopyFiles(s As String, d As String)
        For Each f As String In IO.Directory.GetFiles(s)
          Dim sf As String = IO.Path.Combine(s, IO.Path.GetFileName(f))
          Dim df As String = IO.Path.Combine(d, IO.Path.GetFileName(f))
          IO.File.Copy(sf, df)
          ' IO.File.Move(sf, df)
        Next
      End Sub
    End Class



    Regards Les, Livingston, Scotland



    thank you very much

    Copy files from one folder to another
    But the problem did not transfer to the other folder the name of the first folder to put files in the transfer of files only I want to move the folder and the contents of the same name of the first folder

    Friday, February 16, 2018 10:41 PM
  • Hi

    Sorry, I don't understand.

    You can move or copy files from any (unprotected) folder to any other folder of your choice. When the second folder browser dialog opens, you can use the create button to make the folder name you want.


    Regards Les, Livingston, Scotland

    • Marked as answer by monemas Friday, February 16, 2018 11:15 PM
    Friday, February 16, 2018 10:44 PM
  • Hi

    Sorry, I don't understand.

    You can move or copy files from any (unprotected) folder to any other folder of your choice. When the second folder browser dialog opens, you can use the create button to make the folder name you want.


    Regards Les, Livingston, Scotland

    thank you very much

    Friday, February 16, 2018 11:16 PM