深层目录文件复制,C# 递归,录音录像图片文件过多,用于测试程序

 /// <summary>
/// 录音录像图片文件过多只复制目录的前几个文件,用于测试程序
/// d:\file/images/2019-10/01/01/xxxxx.jpg(前几个文件)
/// 复制到
/// E:\file/images/2019-10/01/01/xxxxx.jpg
///
/// copyfiles("d:\file","e:\file");
/// </summary>
/// <param name="path">源目录</param>
/// <param name="toPath">目的目录</param>
/// <param name="Num">文件个数</param>
public static void CopyFiles(string path,string toPath,int Num)
{
var logger = NLog.LogManager.GetCurrentClassLogger();
DirectoryInfo dir = new DirectoryInfo(path);
DirectoryInfo[] childs = dir.GetDirectories();
string newdirStr;
if (dir.Name.IndexOf(':') == -)
{
DirectoryInfo newdir = Directory.CreateDirectory(toPath + "\\" + dir.Name);
newdirStr = newdir.FullName;
}
else
{
newdirStr = toPath;
}
if (childs.Length>)
{
foreach (var child in childs)
{
if ((child.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
continue;
}
CopyFiles(child.FullName, newdirStr, Num);
}
}
else
{
dir.GetFiles().Take(Num).ToList().ForEach(f => {
string newfilename = newdirStr + "\\" + f.Name;
File.Copy(f.FullName, newfilename, true);
logger.Info($"复制文件:{f.FullName}");
logger.Info($"复制文件:{newfilename}");
});
}
}
上一篇:Keepalived安装配置入门


下一篇:点击盒子选中里面的单选框,并给盒子添加相应样式,美化单选框、复选框样式css用法,响应式滴