• Home
  • About
  • Streaming

xneuron

eXtreme Neuron

Feeds:
Posts
Comments

Copy Directory And Its Content To Another Directory In C#

April 12, 2007 by bnma

    public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
    {
        // Check if the target directory exists, if not, create it.
        if (Directory.Exists(target.FullName) == false)
        {
            Directory.CreateDirectory(target.FullName);
        }

        // Copy each file into it’s new directory.
        foreach (FileInfo fi in source.GetFiles())
        {
            Console.WriteLine(@”Copying {0}\{1}”, target.FullName, fi.Name);
            fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
        }

        // Copy each subdirectory using recursion.
        foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
        {
            DirectoryInfo nextTargetSubDir =
                target.CreateSubdirectory(diSourceSubDir.Name);
            CopyAll(diSourceSubDir, nextTargetSubDir);
        }
    }

Posted in .Net, C# | No Comments Yet

  • Pages

    • About
    • Streaming
  • c

  • Top Posts

    • Copy Directory And Its Content To Another Directory In C#
    • String.Format() In JavaScript As In C#
    • Convert an ArrayList of strings to a string[] array
    • Deserialize XML string
    • X509 Certificate Installation
    • Move Items From One ListBox To Another
    • Page Postbacks And Client Callbacks
    • Launch Cassini Using Command Line
    • File MIME Type Using C#
    • Filtering Non-Numeric Characters In A Textbox Using Javascript
  • Recent Posts

    • Url Validation In Javascript
    • Script To Search Text In Database
    • Launch Cassini Using Command Line
    • Max File Size Upload In ASP.Net
    • File MIME Type Using C#
  • Archives

    • June 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • October 2008
    • August 2008
    • May 2008
    • April 2008
    • February 2008
    • December 2007
    • October 2007
    • September 2007
    • April 2007
    • January 2007
    • November 2006
    • October 2006
    • September 2006
  • Blog Stats

    • 69,064 hits
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.com
  • Watch videos at Vodpod and other videos from this collection.

Blog at WordPress.com.

Theme: Mistylook by Sadish.