?
Solved

Move Contents of Folder to new folder

Posted on 2011-02-16
2
Medium Priority
?
506 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

831 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