?
Solved

Move Contents of Folder to new folder

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

777 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