Geeks With Blogs
Wil Peck Experience is something you get right after you need it.

Really no magic here and just a simple add on to my previous post just in case you  need something that can easily copy the contents of a given directory to another location.

 

public static void CopyContentsTo(this DirectoryInfo source, string desinationDirectory)
{
    if (string.IsNullOrEmpty(desinationDirectory))
    {
        throw new ArgumentNullException("rootDestinationDirectory");
    }

    if (!Directory.Exists(desinationDirectory))
    {
        Directory.CreateDirectory(desinationDirectory);
    }

    foreach (string file in Directory.GetFiles(source.FullName))
    {
        File.Copy(file, Path.Combine(desinationDirectory, Path.GetFileName(file)), true);
    }

    foreach (DirectoryInfo directory in source.GetDirectories())
    {
        CopyTo(directory, desinationDirectory, true);
    }
}

 

Posted on Monday, September 14, 2009 8:40 PM | Back to top


Comments on this post: DirectoryInfo.CopyContentsTo(destinationDirectory)

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Wil Peck | Powered by: GeeksWithBlogs.net