Solved

Move Contents of Folder to new folder

Posted on 2011-02-16
2
497 Views
Last Modified: 2012-05-11
I have an archive folder that has many sub folders. Each subfolder may or maynot contain contents or additional sub folders. What I need to do is to retreive each file from all levels of subfolders in C:\Archive and place in C:\Final. I do not need any subfolder in the new folder, just all files in a single level folder. I am open to C# or VB.Net does not matter. Can anyone assist?
0
Comment
Question by:OB1Canobie
2 Comments
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 34912093
Hi,

Try this.

/peter

public static void Main() {
      recursecopy("C:\\Archive", "C:\\Final");

      Console.ReadKey();
    }

    private static void recursecopy(string source, string target) {
      foreach(string folder in System.IO.Directory.GetDirectories(source)) {
        recursecopy(folder, target);
      }
      foreach(string file in System.IO.Directory.GetFiles(source)) {
        System.IO.File.Copy(file, System.IO.Path.Combine(target, System.IO.Path.GetFileName(file)), true);
      }
    }

Open in new window

0
 

Author Closing Comment

by:OB1Canobie
ID: 34912583
Excellent.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now