c#深拷贝文件夹示例
发布时间:2023-07-24 07:50:40
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace FileUtility
{
public class Program
{
public static void DeepCopy(DirectoryInfo source, DirectoryInfo target, params string[] excludePatterns)
{
if (target.FullName.Contains(source.FullName))
return;
// Go through the Directories and recursively call the DeepCopy Method for each one
foreach (DirectoryInfo dir in source.GetDirectories())
{
var dirName = dir.Name;
var shouldExclude = excludePatterns.Aggregate(false, (current, pattern) => current || Regex.Match(dirName, pattern).Success);
if (!shouldExclude)
DeepCopy(dir, target.CreateSubdirectory(dir.Name), excludePatterns);
}
// Go ahead and copy each file to the target directory
foreach (FileInfo file in source.GetFiles())
{
var fileName = file.Name;
var shouldExclude = excludePatterns.Aggregate(false,
(current, pattern) =>
current || Regex.Match(fileName, pattern).Success);
if (!shouldExclude)
file.CopyTo(Path.Combine(target.FullName, fileName));
}
}
static void Main(string[] args)
{
DeepCopy(new DirectoryInfo(@"d:/test/b"), new DirectoryInfo(@"d:/test/a"));
DeepCopy(new DirectoryInfo(@"d:/test/c"), new DirectoryInfo(@"d:/test/c/c.1"));
DeepCopy(new DirectoryInfo(@"d:/test/1/"), new DirectoryInfo(@"d:/test/2/"), new string[] { ".*\\.txt" });
Console.WriteLine("复制成功...");
Console.ReadKey();
}
}
}


猜你喜欢
- 摘要在生产环境下,我们需要关闭swagger配置,避免暴露接口的这种危险行为。方法禁用方法1:使用注解 @Value() 推荐使用packa
- 我就废话不多说了,大家还是直接看代码吧~import com.alibaba.fastjson.JSON;import java.util.
- Runtime.getRuntime().exec 路径包含空格1. 现象java代码通过Runtime.getRuntime().exec
- 本文介绍在C#窗体编程时,如何设置不显示右上角的最小化最大化关闭按钮。可以通过this.ControlBox这个属性的值来控制。在Windo
- 前言在上一篇学习SpringBoot中,整合了Mybatis、Druid和PageHelper并实现了多数据源的操作。本篇主要是介绍和使用目
- 前言若你的工程还没有进行基础配置,请查看我的博文Unity 之 ShaderGraph入门使用详解,按照步骤操作完成配置即可,还能顺便学习一
- Vitamio是一个功能强大而稳定的播放器库,它支持多种视频格式和编解码方式,并且具有快速、流畅的播放效果,因此在一些对播放质量要求比较高的
- 目录一、前言(1)Timer(2)DelayedQueue 延迟队列(3)ScheduledThreadPoolExecutor(4)Sch
- 题目:求100之内的素数方法一:package airthmatic;public class demo8 { /** * 素数是指因数只有
- 一、Spring Boot Admin 的概念 Spring Boot Admin是一个
- 1.MyBatisX插件在使用mybatis或者mybatis-plus时,我们可以安装IDEA的MyBatis的插件 - MyBatisX
- using System;using System.Collections.Generic;namespace Demo{ &nb
- 前言最近公司有了新的业务,把现有Flutter Android项目应用到TV上去,这不,Asscre的活就来了。本文详细说明Flutter
- 1 MapStruct配置MapStuct的使用非常简单,把对应的jar包引入即可。<properties> &n
- 我们已经写了一些Java程序。之前的每个Java程序都被保存为一个文件,比如Test.java。随后,该程序被编译为Test.class。我
- 前言在数据库连接池分析的代码实例中,看到其中使用Enumeration来遍历Vector集合。后来就找了一些资料查看都有哪些方法可以遍历集合
- 下面以launch方法为例进行分析。一.协程的创建launch方法的代码如下:// CoroutineScope的扩展方法public fu
- 常规调用方式:(这个肯定会弹出cmd窗口)Runtime.getRuntime().exec("cmd.exe &nbs
- 由于处理器核心的增长及较低的硬件成本允许低成本的集群系统,致使如今并行编程无处不在,并行编程似乎是下一个大事件。Java 8 针对这一事实提
- 一、什么是MVP在网上找了些资料,整理如下:MVP是模型(Model)、视图(View)、主持人(Presenter)的缩写,分别代表项目中