Click here to Skip to main content
11,923,517 members (65,185 online)
Click here to Skip to main content
Add your own
alternative version


16 bookmarked

.NET Directory Copy Program

, 24 Jun 2005
Rate this:
Please Sign up or sign in to vote.
The article fills in the gap for the .NET framework to copy directory contents.


This article submitted is my first posting in CodeProject. The code given along side is for the use of copying all the contents of a folder and if needed it can also again try to copy it some where else if the process failed.


The Microsoft .NET framework does not provide for the functionality to copy a directory. This article and the code attached with it solves the particular problem.

Using the code

The heart of all is this function neatly searches the directory and the files and then copies them to a new directory after the definition table is created.

public void DirectorySearch(string strSourceDirectory, 
             string strSourceDirectoryConstant, 
             string strDestinationDirectory)
    string [] strarrDirectoryNames= Directory.GetDirectories(strSourceDirectory);
    string [] strarrFileNames= Directory.GetFiles(strSourceDirectory);
    foreach(string strFileName in strarrFileNames)
            FileInfo info=new FileInfo(strFileName);
            long fileLength= info.Length;
            totalLength =totalLength+fileLength;
            //Below the function Insert is used which 
            //is found in the code : purpose to store the data
            Insert("FILE", strFileName, strSourceDirectoryConstant + @"\" + 
                   info.Name, fileLength.ToString(), strDestinationDirectory);
    foreach(string strDirectoryName in strarrDirectoryNames)
        DirectoryInfo info=new DirectoryInfo(strDirectoryName);
        DirectorySearch(strDirectoryName, strSourceDirectoryConstant 
                        + @"\" + info.Name, strDestinationDirectory);
        Insert("DIRECTORY", strDirectoryName, strSourceDirectoryConstant 
               + @"\" + info.Name, "", strDestinationDirectory);


  • Version 1.0 - 5:19 PM 6/20/2005.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
I am working as a software professional in YASH Technologies in hyderabad india.
I primarly Work in Pocket PC projects

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
yasser_abbasi12-Feb-10 1:50
memberyasser_abbasi12-Feb-10 1:50 
General:S Pin
ADakage31-Jan-09 23:27
memberADakage31-Jan-09 23:27 
QuestionSHFileOperation? Pin
Nishant Sivakumar24-Jun-05 1:15
staffNishant Sivakumar24-Jun-05 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151125.3 | Last Updated 24 Jun 2005
Article Copyright 2005 by Aryasheel
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid