WinForm (C \ #) 폴 더 복사

1876 단어 WinForm
C: \ abc 폴 더 를 D: \ 아래로 복사 하려 면 어떻게 해 야 합 니까?
 
using System.IO; 
 
 /// <summary>

        ///      

        /// </summary>

        /// <param name="srcdir"></param>

        /// <param name="desdir"></param>

        private void CopyDirectory(string srcdir, string desdir)

        {

            string folderName = srcdir.Substring(srcdir.LastIndexOf("\\")+1);



            string desfolderdir = desdir +"\\"+ folderName;



            if (desdir.LastIndexOf("\\") == (desdir.Length - 1))

            {

                desfolderdir = desdir + folderName;

            }

            string[] filenames = Directory.GetFileSystemEntries(srcdir);



            foreach (string file in filenames)//           

            {

                if (Directory.Exists(file))//                   Copy        

                {



                    string currentdir = desfolderdir + "\\" + file.Substring(file.LastIndexOf("\\") + 1);

                    if (!Directory.Exists(currentdir))

                    {

                        Directory.CreateDirectory(currentdir);

                    }



                    CopyDirectory(file, desfolderdir);

                }



                else //     copy  

                {

                    string srcfileName = file.Substring(file.LastIndexOf("\\")+1);



                    srcfileName = desfolderdir + "\\" + srcfileName;





                    if (!Directory.Exists(desfolderdir))

                    {

                        Directory.CreateDirectory(desfolderdir);

                    }

                    

                    

                    File.Copy(file, srcfileName);

                }

            }//foreach 

}//function end

좋은 웹페이지 즐겨찾기