zoukankan      html  css  js  c++  java
  • 深层目录文件复制,C# 递归,录音录像图片文件过多,用于测试程序

     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         }
  • 相关阅读:
    第四次实践作业
    第三次实践作业
    第二次实践作业
    第一次实践作业
    第02组 Beta版本演示
    第02组 Beta冲刺(4/4)
    大数据应用技术课程实践--选题与实践方案
    15 手写数字识别-小数据集
    14 深度学习-卷积
    13 垃圾邮件分类2
  • 原文地址:https://www.cnblogs.com/mingjing/p/11354092.html
Copyright © 2011-2022 走看看