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. 从UI设计转向前端的艰辛过程,从背单词开始。。。

    很纠结到底是继续做UI设计还是转行前端呢?从刚开始的害怕代码到接触代码又喜欢代码的过程,我在想我是不是太飘了,我感觉我做事就是三分钟热度.我感觉学前端对我最大的阻碍就是英语单词了,10个单词里面最起码 ...

  2. ThreadLocal 源码解读

    一.引入 public class Thread implements Runnable { /* 前面略 */ /* ThreadLocal values pertaining to this th ...

  3. 共享共建会让中国的5G加速吗?

    9月9号,中国联通正式公告,已与中国电信签署<5G网络共建共享框架合作协议书>,将在全国范围内合作共建5G接入网络. 这则消息堪称爆炸性新闻,但却看不到什么深度分析,评论文章除了强调&qu ...

  4. Charles Fiddler使用

    http://blog.devtang.com/2015/11/14/charles-introduction/ Charles 从入门到精通 http://www.infoq.com/cn/arti ...

  5. iOS开发之UIWebView

    转自:http://www.cnblogs.com/zhuqil/archive/2011/07/28/2119923.html UIWebView是iOS sdk中一个最常用的控件.是内置的浏览器控 ...

  6. AutoLayout的那些事儿

    转自:http://www.cocoachina.com/ios/20160530/16522.html 本文投稿文章,作者:MangoMade(简书) AutoLayout非常强大也非常易用,可读性 ...

  7. Cookie俩步操作实现n天免登陆

    实现这个功能主要思路是:在登录成功的时候去给用户名和密码加上Cookie,将他们的值存在Cookie中,为了下次登录记住用户名和密码,然后在登录界面,获取所有的cookie,然后将值一一遍历出来.和用 ...

  8. iSensor APP 之 摄像头调试 OV9655

    iSensor APP 之 摄像头调试  OV9655 iSensor app 非常适合调试各种摄像头,已测试通过的sensor有: l  OV7670.OV7725.OV9650.OV9655.OV ...

  9. v-if和v-show 的区别

    区别 1.手段:v-if是通过控制dom节点的存在与否来控制元素的显隐:v-show是通过设置DOM元素的display样式,block为显示,none为隐藏: 2.编译过程:v-if切换有一个局部编 ...

  10. mysql取消严格模式

    配置文件my.ini sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 修改为 s ...