c# 复制文件夹及其文件

网上找到的,以备以后使用
private void Copy()
        {
                DirectoryInfo dir = new DirectoryInfo( "c:\\CSS");
                CopyDirectorysAndFiles( "c:\\test", dir);
        }

         private void CopyDirectorysAndFiles( string dest, DirectoryInfo srcdir)
        {
                 if (dest.LastIndexOf('\\') != (dest.Length - 1))
                {
                        dest += "\\";
                }
                 string destPath = dest +srcdir.Name + "\\";
                 if (!Directory.Exists(destPath))
                {
                     Directory.CreateDirectory(destPath);
                }
                FileInfo[] files = srcdir.GetFiles();
                 foreach (FileInfo file in files)
                {
                        file.CopyTo(destPath + file.Name, true);
                }
                DirectoryInfo[] dirs = srcdir.GetDirectories();
                 foreach (DirectoryInfo dirInfo in dirs)
                {
                        CopyDirectorysAndFiles(destPath, dirInfo);
                }
        }    

你可能感兴趣的:(职场,C#,复制文件,休闲)