Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Move All Files in a directory

Using C#, how would I copy out all files in a directory and move to another folder?
0
carsRST
Asked:
carsRST
  • 2
  • 2
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
0
 
käµfm³d 👽Commented:
It could be as simple as:

using System.IO;

namespace _27412501
{
    class Program
    {
        static void Main(string[] args)
        {
            string targetDir = @"C:\path\to\new\folder";
            DirectoryInfo folder = new DirectoryInfo(@"C:\path\to\folder");

            foreach (FileInfo file in folder.GetFiles())
            {
                file.CopyTo(Path.Combine(targetDir, file.Name));
            }
        }
    }
}

Open in new window

0
 
käµfm³d 👽Commented:
If you want to actually move them, then you can use MoveTo instead of CopyTo.
0
 
carsRSTAuthor Commented:
thanks again!
0
 
carsRSTAuthor Commented:
>>If you want to actually move them, then you can use MoveTo instead of CopyTo.

thx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now