private static void PathCopyFilesWithOriginalFolder()
{
int sourceFilesNum = ;
try
{
string sourceDir = @"E:\Source";
string destDir = @"E:\Dest";
string[] allSourceFiles = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories);
if (allSourceFiles != null && allSourceFiles.Any())
{
foreach (var sourceFileFullName in allSourceFiles)
{
string sourceFileDir = Path.GetDirectoryName(sourceFileFullName);
string sourceFileRelativeDir = string.Empty;
if (sourceFileDir.Length > sourceDir.Length)
{
sourceFileRelativeDir = sourceFileDir.Substring(sourceDir.Length + );
}
else
{
sourceFileRelativeDir = "";
}
string destFileDir = Path.Combine(destDir, sourceFileRelativeDir);
if (!Directory.Exists(destFileDir))
{
Directory.CreateDirectory(destFileDir);
} string destFileFullName = Path.Combine(destFileDir, Path.GetFileName(sourceFileFullName));
File.Copy(sourceFileFullName, destFileFullName, true);
string msg = $"SourceFileFullName:{sourceFileFullName},DestFileFullName:{destFileFullName}";
Console.WriteLine(msg);
sourceFilesNum++;
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
System.Diagnostics.Debug.WriteLine(sourceFilesNum);
}
}

C# copy source directory files with original folder to the destination path的更多相关文章

  1. [转]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 ...

  2. convert source code files to pdf format in python

    import os import sys def find_file(root_dir, type): dirs_pool = [root_dir] dest_pool = [] def scan_d ...

  3. angular.copy(source, destination)

    angular.copy(source, destination)只有1个参数,返回source的深拷贝有2个参数source的深拷贝复制给destination

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

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

  5. mysql配置文件夹错误:在安装mysql 5.6.19 时运行cmake命令是出现CMake Error: The source directory does not appear to contai

    在安装mysql 5.5.xx 时运行cmake命令是出现CMake Error: The source directory does not appear to contain CMakeLists ...

  6. 解决Cannot find config.m4 Make sure that you run '/home/php/bin/phpize' in the top level source directory of the module

    oot@DK:/home/daokr/downfile/php-7.0.0/ext/mysqlnd# /home/php/bin/phpizeCannot find config.m4. Make s ...

  7. how to recursively all files in a folder with sudo permissions in macOS

    how to recursively all files in a folder with sudo permissions in macOS write bug OK sudo chmod 777 ...

  8. C# copy files from source directory to destination file and rename repeated files and does not override

    static void CopyFiles() { string sourceDir = @"D:\C\ll"; string destDir = @"D:\LL&quo ...

  9. [转]How to Use xp_dirtree to List All Files in a Folder

    本文转自:http://www.sqlservercentral.com/blogs/everyday-sql/2012/11/13/how-to-use-xp_dirtree-to-list-all ...

随机推荐

  1. php踩过的那些坑(3) 数据类型转换

    一.前方有坑 php属于弱类型语言,不会强迫工程师在使用变量之前先声明变量类型,开发时爽了,但是也带来不少的坑.下面就举一个坑的例子: 例1: $str = ‘haodaquan'; echo ($s ...

  2. 第三章 学习Shader所需的数学基础(5)

    1. Unity Shader的内置变量(数学篇) 使用Unity写shader的一个好处在于,它提供了很多内置参数,这使得我们不在需要自己手动算一些值.本文给出Unity内置的用于空间变换和摄像机以 ...

  3. Spring Boot 2.0 学习笔记(一)——JAVA EE简介

    本章内容:JAVA EE>Spring>Spring Boot 一.JAVA EE简介 1.1 Java ee优点:结束了Web开发的技术无序状态,让程序员.架构师用同一种思维去思考如何架 ...

  4. Flask使用bootstrap为HttpServer添加上传文件功能

    关于模态框 使用bootstrap实现点击按钮弹出窗口,简直不要太简单.我们只需要将写好的窗口内容隐藏,然后调用bootstrap的框架即可,简单几行就能完成相关功能实现.... 前提条件是,我们需要 ...

  5. 充满含金量的一场云原生Meetup,入场券免费发送中……

    在武汉,你离这场云原生盛会,只有一步之遥 华为云.百度.斗鱼.海云基因,五位重量级专家 K8s调度.深度学习平台.斗鱼实战.基因大数据-五个干货议题 日,与您相约Cloud Native Days C ...

  6. 大型情感剧集Selenium:4_老中医教你(单/多/下拉框)选项定位 #华为云·寻找黑马程序员#

    今天讲什么 讲什么标题说了,讲selenium的单选.多选.下拉框选项定位.但其实这东西,没什么太多说的,又比较枯燥,那该怎么让这一集selenium的课程变得有趣呢?有请老中医,哈哈- 怎么样,这个 ...

  7. PyTorch最佳实践,怎样才能写出一手风格优美的代码

    [摘要] PyTorch是最优秀的深度学习框架之一,它简单优雅,非常适合入门.本文将介绍PyTorch的最佳实践和代码风格都是怎样的. 虽然这是一个非官方的 PyTorch 指南,但本文总结了一年多使 ...

  8. 华为OSPF与ACL综合应用实例讲解

    OSPF与ACL综合应用实例讲解 项目案例要求: 1.企业内网运行OSPF路由协议,区域规划如图所示:2.财务和研发所在的区域不受其他区域链路不稳定性影响:3.R1.R2.R3只允许被IT登录管理:4 ...

  9. HDU3247 Resource Archiver (AC自动机+spfa+状压DP)

    Great! Your new software is almost finished! The only thing left to do is archiving all your n resou ...

  10. B.Silly Mistake

    题目:愚蠢的错误 题意:中心公司有一个办公室有一个成熟的安全系统,这里面有10^6个雇员,编号从1到10^6 安全系统有入口和出口,数字i表示第i个雇员进入,-i表示第i个雇员出去 公司有一些严格的规 ...