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. C#
  4. Copying files from folder to another

Copying files from folder to another

Scheduled Pinned Locked Moved C#
csharptutorial
8 Posts 5 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.
  • Y Offline
    Y Offline
    ysunil_74
    wrote on last edited by
    #1

    How to copy all files from one folder to another at a time in C#.net

    A 1 Reply Last reply
    0
    • Y ysunil_74

      How to copy all files from one folder to another at a time in C#.net

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

      use System.IO FileInfo Class , and File.Copy() method . Hope this hits will help you ;)

      Best Regards ----------------- Abhijit Jana View My Latest Article :- SpyNet : Your Network Spy "Success is Journey it's not a destination"

      Y 1 Reply Last reply
      0
      • A Abhijit Jana

        use System.IO FileInfo Class , and File.Copy() method . Hope this hits will help you ;)

        Best Regards ----------------- Abhijit Jana View My Latest Article :- SpyNet : Your Network Spy "Success is Journey it's not a destination"

        Y Offline
        Y Offline
        ysunil_74
        wrote on last edited by
        #3

        file.copy only copies one file but i want to copy all files in a folder to another folder at a time

        J A V 3 Replies Last reply
        0
        • Y ysunil_74

          file.copy only copies one file but i want to copy all files in a folder to another folder at a time

          J Offline
          J Offline
          JF2015
          wrote on last edited by
          #4

          Hi, this is also easy to do:

          foreach(string file in System.IO.Directory.GetFiles(path))
          {
          File.Copy(....);
          }

          1 Reply Last reply
          0
          • Y ysunil_74

            file.copy only copies one file but i want to copy all files in a folder to another folder at a time

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

            You have got the answer :)

            Best Regards ----------------- Abhijit Jana View My Latest Article :- SpyNet : Your Network Spy "Success is Journey it's not a destination"

            Y 1 Reply Last reply
            0
            • A Abhijit Jana

              You have got the answer :)

              Best Regards ----------------- Abhijit Jana View My Latest Article :- SpyNet : Your Network Spy "Success is Journey it's not a destination"

              Y Offline
              Y Offline
              ysunil_74
              wrote on last edited by
              #6

              Hi, I got the answer . Thank u I Modified the code a little : DirectoryInfo df = new DirectoryInfo(@"C:\Inetpub\wwwroot\Sample\images"); foreach(FileInfo f in df.GetFiles()) { string p = f.FullName.Replace("images", "New Folder"); File.Create(p); }

              J 1 Reply Last reply
              0
              • Y ysunil_74

                file.copy only copies one file but i want to copy all files in a folder to another folder at a time

                V Offline
                V Offline
                Vasudevan Deepak Kumar
                wrote on last edited by
                #7

                ysunil_74 wrote:

                but i want to copy all files in a folder

                What prevents you from iterating through the list of files returned through .GetFiles()?

                Vasudevan Deepak Kumar Personal Homepage
                Tech Gossips
                A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                1 Reply Last reply
                0
                • Y ysunil_74

                  Hi, I got the answer . Thank u I Modified the code a little : DirectoryInfo df = new DirectoryInfo(@"C:\Inetpub\wwwroot\Sample\images"); foreach(FileInfo f in df.GetFiles()) { string p = f.FullName.Replace("images", "New Folder"); File.Create(p); }

                  J Offline
                  J Offline
                  J4amieC
                  wrote on last edited by
                  #8

                  ysunil_74 wrote:

                  string p = f.FullName.Replace("images", "New Folder"); File.Create(p);

                  That just creates an empty file in a different location :confused: and will also cause interesting side effects if the filename has the string "images" in it.

                  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