Copy Dir - CSharp System.IO

CSharp examples for System.IO:DirectoryInfo

Description

Copy Dir

Demo Code


using System.IO;/* w  w  w  .ja va  2s.c  o m*/
using System;

public class Main{
        /// <summary>
        /// ?????? 
        /// </summary>
        /// <param name="strFromDirectory"></param>
        /// <param name="strToDirectory"></param>
        /// <returns></returns>
        public static bool CopyDir(string strFromDirectory, string strToDirectory)
        {
            Directory.CreateDirectory(strToDirectory);
            if (!Directory.Exists(strFromDirectory))
            {
                return false;
            }
            string[] directories = Directory.GetDirectories(strFromDirectory);
            if (directories.Length > 0)
            {
                string[] array = directories;
                for (int i = 0; i < array.Length; i++)
                {
                    string text = array[i];
                    CopyDir(text, strToDirectory + text.Substring(text.LastIndexOf("\\")));
                }
            }
            string[] files = Directory.GetFiles(strFromDirectory);
            if (files.Length > 0)
            {
                string[] array2 = files;
                for (int j = 0; j < array2.Length; j++)
                {
                    string text2 = array2[j];
                    File.Copy(text2, strToDirectory + text2.Substring(text2.LastIndexOf("\\")));
                }
            }
            return true;
        }
}

Related Tutorials