深层目录文件复制,C# 递归,录音录像图片文件过多,用于测试程
发布时间:2020-12-16 01:25:46 所属栏目:百科 来源:网络整理
导读:? ? 1 /// summary 2 /// 录音录像图片文件过多只复制目录的前几个文件,用于测试程序 3 /// d:file/images/2019-10/01/01/xxxxx.jpg(前几个文件) 4 /// 复制到 5 /// E:file/images/2019-10/01/01/xxxxx.jpg 6 /// 7 /// copyfiles("d:file","e:file"
? ? 1 /// <summary> 2 /// 录音录像图片文件过多只复制目录的前几个文件,用于测试程序 3 /// d:file/images/2019-10/01/01/xxxxx.jpg(前几个文件) 4 /// 复制到 5 /// E:file/images/2019-10/01/01/xxxxx.jpg 6 /// 7 /// copyfiles("d:file","e:file"); 8 /// </summary> 9 /// <param name="path">源目录</param> 10 /// <param name="toPath">目的目录</param> 11 /// <param name="Num">文件个数</param> 12 public static void CopyFiles(string path,string toPath,int Num) 13 { 14 var logger = NLog.LogManager.GetCurrentClassLogger(); 15 DirectoryInfo dir = new DirectoryInfo(path); 16 DirectoryInfo[] childs = dir.GetDirectories(); 17 string newdirStr; 18 if (dir.Name.IndexOf(‘:‘) == -1) 19 { 20 DirectoryInfo newdir = Directory.CreateDirectory(toPath + "" + dir.Name); 21 newdirStr = newdir.FullName; 22 } 23 else 24 { 25 newdirStr = toPath; 26 } 27 if (childs.Length>0) 28 { 29 foreach (var child in childs) 30 { 31 if ((child.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) 32 { 33 continue; 34 } 35 CopyFiles(child.FullName,newdirStr,Num); 36 } 37 } 38 else 39 { 40 dir.GetFiles().Take(Num).ToList().ForEach(f => { 41 string newfilename = newdirStr + "" + f.Name; 42 File.Copy(f.FullName,newfilename,true); 43 logger.Info($"复制文件:{f.FullName}"); 44 logger.Info($"复制文件:{newfilename}"); 45 }); 46 } 47 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- oracle的序列号(sequence)
- java – 同意Xcode / iOS许可证需要管理员权限,请以root身份
- 用 alibaba 的 fastjson 将 list 或 map 转为 json 字符串
- 纯Ajax实现Google Suggest功能。
- c# – 鼠标输入和鼠标在表单上保留
- Neo4j索引笔记之SchemaIndex和LegacyIndex
- 【转】Flash Android ANE 多个jar包和资源的处理
- ruby-on-rails – 无论如何使用Active Admin添加其他级别的
- Camera学习笔记(一):camera_preferences.xml分析
- 用postgresql(postgis) 查找指定范围内的兴趣点