在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
使用递归的方式将文件夹内所有内容复制到新的路径
1 public void CopyDirectory(string scrPath, string savePath) 2 { 3 if (Directory.Exists(scrPath))//检查路径(目录)是否存在 4 { 5 if (!Directory.Exists(savePath)) 6 Directory.CreateDirectory(savePath); 7 string[] sdd = DateTime.Now.GetDateTimeFormats(); 8 string subSavePath = savePath + "\\" + DateTime.Now.GetDateTimeFormats()[10]; 9 Directory.CreateDirectory(savePath + "\\" + DateTime.Now.GetDateTimeFormats()[10]); 10 11 string[] aFiles = Directory.GetFiles(scrPath); 12 string[] aDirectory = Directory.GetDirectories(scrPath); 13 for (int i = 0; i < aFiles.Length; i++) 14 { 15 FileInfo fi = new FileInfo(aFiles[i]); 16 long fileSize = fi.Length;//文件大小 17 18 File.Copy(aFiles[i], subSavePath + "\\" + fi.Name); 19 } 20 if (aDirectory.Length != 0) 21 { 22 for (int i = 0; i < aDirectory.Length; i++) 23 { 24 string aName = aDirectory[i].Substring(aDirectory[i].LastIndexOf('\\')); 25 CopyDirectory(aDirectory[i], subSavePath + aName); 26 } 27 } 28 } 29 } 30 }
|
请发表评论