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. Moving the multiple files from one to another location

Moving the multiple files from one to another location

Scheduled Pinned Locked Moved C#
xml
6 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.
  • A Offline
    A Offline
    annie_bel
    wrote on last edited by
    #1

    hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards

    N I L 3 Replies Last reply
    0
    • A annie_bel

      hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards

      N Offline
      N Offline
      Nuri Ismail
      wrote on last edited by
      #2

      You can move your files at once by using SHFileOperation API. This[^] is a very good article that describes how you can use this API in C#. One of the examples in the article shows exactly how to move multiple files. :)

      1 Reply Last reply
      0
      • A annie_bel

        hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards

        I Offline
        I Offline
        Islorvat
        wrote on last edited by
        #3

        Here is how i would do it:

               foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) 
                {
                    if (f.EndsWith(".xml")) 
                    {
                        string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); 
                        File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); 
                    }
                }
        

        It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.

        A 2 Replies Last reply
        0
        • I Islorvat

          Here is how i would do it:

                 foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) 
                  {
                      if (f.EndsWith(".xml")) 
                      {
                          string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); 
                          File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); 
                      }
                  }
          

          It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.

          A Offline
          A Offline
          annie_bel
          wrote on last edited by
          #4

          Thank you vey much! Islorvat but if my file already exist in destination,then... with regards

          modified on Wednesday, August 11, 2010 7:35 AM

          1 Reply Last reply
          0
          • A annie_bel

            hi! I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory. I had already done one file but i couldn't move multiple xml files. please do my favour. thanx & regards

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you may want to read up on the System.IO.Path[^] class, which offers methods to deal with file paths. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            1 Reply Last reply
            0
            • I Islorvat

              Here is how i would do it:

                     foreach (string f in Directory.GetFiles(@"C:\\MyFolder")) 
                      {
                          if (f.EndsWith(".xml")) 
                          {
                              string currentf = f.Substring(f.LastIndexOf('\\\\') + 1); 
                              File.Move(f, @"C:\\MyFolder\\MyXmlFolder\\" + currentf); 
                          }
                      }
              

              It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.

              A Offline
              A Offline
              annie_bel
              wrote on last edited by
              #6

              Thanx, I resolved my problems

              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