Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Copy files from one folder to another

Copy files from one folder to another

Scheduled Pinned Locked Moved Visual Basic
help
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VB Net Developer
    wrote on last edited by
    #1

    I need to copy all files from one file to another..Could someon help

    T E A 3 Replies Last reply
    0
    • V VB Net Developer

      I need to copy all files from one file to another..Could someon help

      T Offline
      T Offline
      Tamimi Code
      wrote on last edited by
      #2

      check System.IO.Directory.GetFiles() System.IO.File.Copy()

      When you get mad...THINK twice that the only advice Tamimi - Code

      1 Reply Last reply
      0
      • V VB Net Developer

        I need to copy all files from one file to another..Could someon help

        E Offline
        E Offline
        Eric Georgiades
        wrote on last edited by
        #3

        If you're using VB.NET 2005, you can use that handly little "My": For Each sfile As String In My.Computer.FileSystem.GetFiles( My.Computer.FileSystem.SpecialDirectories.MyDocuments,FileIO.SearchOption.SearchAllSubDirectories,"*.*") My.Computer.FileSystem.CopyFile(sFile, "C:\Lalala") Next

        me, myself and my blog - loadx.org ericos g.

        V 1 Reply Last reply
        0
        • E Eric Georgiades

          If you're using VB.NET 2005, you can use that handly little "My": For Each sfile As String In My.Computer.FileSystem.GetFiles( My.Computer.FileSystem.SpecialDirectories.MyDocuments,FileIO.SearchOption.SearchAllSubDirectories,"*.*") My.Computer.FileSystem.CopyFile(sFile, "C:\Lalala") Next

          me, myself and my blog - loadx.org ericos g.

          V Offline
          V Offline
          VB Net Developer
          wrote on last edited by
          #4

          Could you please explain wat is going on

          E 1 Reply Last reply
          0
          • V VB Net Developer

            Could you please explain wat is going on

            E Offline
            E Offline
            Eric Georgiades
            wrote on last edited by
            #5

            sure :) to find all the files in a folder, and do something with each file (like copy them) i used the "For Each" statement. For Each sfile As String In My.Computer.FileSystem.GetFiles( .. so sfile is a string with all the filenames located in the specified folder (in my case, My Documents) My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyDocuments, FileIO.SearchOption.SearchAllSubDirectories, "*.*") or could be anything, like My.Computer.FileSystem.GetFiles("C:\Tatata") then each file was given the command to be copied to "C:\Lalala" My.Computer.FileSystem.CopyFile(sFile, "C:\Lalala") and then ends the loop: Next i hope that helps.

            me, myself and my blog - loadx.org ericos g.

            V 1 Reply Last reply
            0
            • E Eric Georgiades

              sure :) to find all the files in a folder, and do something with each file (like copy them) i used the "For Each" statement. For Each sfile As String In My.Computer.FileSystem.GetFiles( .. so sfile is a string with all the filenames located in the specified folder (in my case, My Documents) My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyDocuments, FileIO.SearchOption.SearchAllSubDirectories, "*.*") or could be anything, like My.Computer.FileSystem.GetFiles("C:\Tatata") then each file was given the command to be copied to "C:\Lalala" My.Computer.FileSystem.CopyFile(sFile, "C:\Lalala") and then ends the loop: Next i hope that helps.

              me, myself and my blog - loadx.org ericos g.

              V Offline
              V Offline
              VB Net Developer
              wrote on last edited by
              #6

              Thanks a lot....That was my requirement i will try it outt

              1 Reply Last reply
              0
              • V VB Net Developer

                I need to copy all files from one file to another..Could someon help

                A Offline
                A Offline
                Abhijit Jana
                wrote on last edited by
                #7

                This Function can do for u !!!! :laugh::laugh: Imports System.IO Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String) Dim dirInfo As New DirectoryInfo(strSrc) Dim fsInfo As FileSystemInfo If Not Directory.Exists(strDest) Then Directory.CreateDirectory(strDest) End If For Each fsInfo In dirInfo.GetFileSystemInfos Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name) If TypeOf fsInfo Is FileInfo Then File.Copy(fsInfo.FullName, strDestFileName, True) 'This will overwrite files that already exist Else CopyDir(fsInfo.FullName, strDestFileName) End If Next End Sub While Copying , if the source dir content large file your GUI will be hanged,,,, so u can use Background worker along with that methods

                Happy Programming ----- Abhijit

                V 1 Reply Last reply
                0
                • A Abhijit Jana

                  This Function can do for u !!!! :laugh::laugh: Imports System.IO Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String) Dim dirInfo As New DirectoryInfo(strSrc) Dim fsInfo As FileSystemInfo If Not Directory.Exists(strDest) Then Directory.CreateDirectory(strDest) End If For Each fsInfo In dirInfo.GetFileSystemInfos Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name) If TypeOf fsInfo Is FileInfo Then File.Copy(fsInfo.FullName, strDestFileName, True) 'This will overwrite files that already exist Else CopyDir(fsInfo.FullName, strDestFileName) End If Next End Sub While Copying , if the source dir content large file your GUI will be hanged,,,, so u can use Background worker along with that methods

                  Happy Programming ----- Abhijit

                  V Offline
                  V Offline
                  VB Net Developer
                  wrote on last edited by
                  #8

                  This works perfectly fine...Thanks a lot

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups