static void Main(string[] args)
{
string sourceDir = @"E:\SourcePath";
string destDir = @"E:\Dest";
CopyDirectoriesFiles(sourceDir, destDir);
Console.ReadLine();
} public static void CopyDirectoriesFiles(string sourceDirectory, string targetDirectory)
{
var diSource = new DirectoryInfo(sourceDirectory);
var diTarget = new DirectoryInfo(targetDirectory);
CopyAll(diSource, diTarget);
} public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
Directory.CreateDirectory(target.FullName); // Copy each file into the new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
} // Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}

C# copy folder and files from source path to target path的更多相关文章

  1. [PowerShell] Backup Folder and Files Across Network

    ## This Script is used to backup folder/files and delete the old backup files. ## Author: Stefanie # ...

  2. [转]COPY OR MOVE FILES AND FOLDERS USING OLE AUTOMATION

    本文转自:http://sqlindia.com/copy-move-files-folders-using-ole-automation-sql-server/ I love playing aro ...

  3. gen already exists but is not a source folder. Convert to a source folder or rename it.

    异常提示: gen already exists but is not a source folder. Convert to a source folder or rename it.   错误原因 ...

  4. 在Eclipse工具里创建maven的web工程,在建立src/main/java包出现The folder is already a source folder.解决

    1. 与创建普通java工程一样,点击右键找到New菜单,在弹出的界面输入maven ---->>点击maven Project------>>点击next 2  进入下一个界 ...

  5. 使用maven新建类目录是,报错The folder is already a source folder.的解决办法

    转自:https://www.cnblogs.com/loger1995/p/6539139.html 我们有时候新建一个webapp的maven项目时,生成的目录结构是这样子的: 缺少maven规范 ...

  6. maven出错The folder is already a source folder

    右键build path -> configure build path -> source ,选择 src/main/java.src/test/java删除,然后再新建.

  7. The folder is already a source folder

    不知为啥,创建了一个maven项目后,发现只有src/main/resources这个资源文件夹,然后,右键新建 Source Folder 时提示 “The folder is already a ...

  8. depth: working copy\infinity\immediates\files\empty

    depth: working copy\infinity\immediates\files\empty 有时间,需要整理下,svn 合并深度这四项:具体的意思.

  9. 出现The folder is already a source folder

    右键build path -> configure build path -> source ,选择 src/main/java.src/test/java删除,然后再新建.

随机推荐

  1. Vue-Router中History模式【华为云分享】

    [摘要] vue-router的history模式的服务端支持 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园地址:<大史住在大前端> ...

  2. java基础-泛型举例详解

    泛型 泛型是JDK5.0增加的新特性,泛型的本质是参数化类型,即所操作的数据类型被指定为一个参数.这种类型参数可以在类.接口.和方法的创建中,分别被称为泛型类.泛型接口.泛型方法. 一.认识泛型 在没 ...

  3. MySQL的存储(一、连接数据库)

    准备工作: 确保安装MySql 安装PyMySQL库 连接数据库: 这里首先尝试连接下数据库,假设当前MySQL运行在本地,用户名为root,密码为123456,运行端口为3306. 通过PyMySQ ...

  4. 论文阅读 | Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks

    简述 在文本语义相似度等句子对的回归任务上,BERT , RoBERTa 拿到sota. 但是,它要求两个句子都被输入到网络中,从而导致巨大开销:从10000个句子集合中找到最相似的sentence- ...

  5. 【CSS】309- 复习 CSS盒模型

    点击上方"前端自习课"关注,学习起来~ 一.概念 CSS盒模型本质上是一个盒子,封装周围的HTML元素,它包括:外边距(margin).边框(border).内边距(padding ...

  6. 浅谈Redis面试热点之工程架构篇[1]

    前言 前面用两篇文章大致介绍了Redis热点面试中的底层实现相关的问题,感兴趣的可以回顾一下:[决战西二旗]|Redis面试热点之底层实现篇[决战西二旗]|Redis面试热点之底层实现篇(续) 接下来 ...

  7. JS四种判断数据类型的方法:typeof、instanceof、constructor、Object.prototype.toString.call()

    1.typeof 1 console.log(typeof ""); //string 2 console.log(typeof 1); //number 3 console.lo ...

  8. 3年java开发面试BAT,你必须彻底搞定Maven!

    前言 现在的Java项目中,Maven随处可见. Maven的仓库管理.依赖管理.继承和聚合等特性为项目的构建提供了一整套完善的解决方案,如果你搞不懂Maven,那么一个多模块的项目足以让你头疼,依赖 ...

  9. cannot resolve symbol AppCompatActivity

    记一次配置性的问题 今天复习自定义控件的时候新建一个project,生成的代码冒红,可把我给郁闷了.我知道我的配置是正确的,可是... 它出现了cannot resolve symbol AppCom ...

  10. DataTable和DataReader的遍历

    1.DataTable的遍历 //创建数据表 DataTable dt = GetDataTable("select * from Student"); //存储数据 String ...