Solved

Move Contents of Folder to new folder

Posted on 2011-02-16
2
502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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