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         }
  • 相关阅读:
    winform 异步更新ui
    定时器的写法 winform
    延迟加载
    使用VS分析程序性能
    win7 C/C++,QT安装环境总结
    论文总结
    天舟一号
    硬盘 SMART 检测参数详解[转]
    碧桃花
    在C的头文件中定义的结构体,如何在cpp文件中引用
  • 原文地址:https://www.cnblogs.com/mingjing/p/11354092.html
Copyright © 2011-2022 走看看