Wil Peck

Experience is something you don't get until just after you need it.


News


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);
    }
}

 


Comments

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: