C# copy source directory files with original folder to the destination path
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的更多相关文章
- [转]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 ...
- 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 ...
- angular.copy(source, destination)
angular.copy(source, destination)只有1个参数,返回source的深拷贝有2个参数source的深拷贝复制给destination
- depth: working copy\infinity\immediates\files\empty
depth: working copy\infinity\immediates\files\empty 有时间,需要整理下,svn 合并深度这四项:具体的意思.
- 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 ...
- 解决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 ...
- 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 ...
- 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 ...
- [转]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 ...
随机推荐
- 基于antd封装一个高可用form组件 减少cv代码导致的bug
引言 在开发中台过程中 我们的原型中有很多表单,antd有表单组件,但是粒度比较细,就单纯组件而言,无可厚非,但是在开发过程中,可能会造成代码不够聚合,有些表单公共逻辑无法提取,copy paste比 ...
- 转:轻松把玩HttpClient之封装HttpClient工具类(一)(现有网上分享中的最强大的工具类)
搜了一下网络上别人封装的HttpClient,大部分特别简单,有一些看起来比较高级,但是用起来都不怎么好用.调用关系不清楚,结构有点混乱.所以也就萌生了自己封装HttpClient工具类的想法.要做就 ...
- 淘宝适配 flexible.js
1.引入 阿里cdm文件,也可以自己下载下来引用,不需要在添加<meta name="viewport"">标签了 <script src=" ...
- Table表格滑过当前项[当前行][当前列]对应高亮
效果演示图: JS 代码如下: function TableHover($table){ $table.mouseenter(function(event) { va ...
- Java修炼——FileInputStream和FileOutputStream
文件字节流FileInputStream是读文件内容 有一下五个方法 1) abstract int read( ); 2) int read( byte b[ ] ); 3) int read( b ...
- CodeForces1006E- Military Problem
E. Military Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- ceph 网络配置
ceph 网络配置 9. 分离 public network 和 cluster network 9.1 分离的好处 (1)提高性能:消除副本创建.数据恢复和再平衡对 public network 的 ...
- java虚拟机运行内存图
首先针对8种常见数据类型(byte,short,int,long,double,float,char,boolean),还有String,他们在类对象被引用的时候,把数据类型存放在栈中,而常量则放在常 ...
- Webpack基础知识总结
本文将从多个方面回顾下自己了解的Webpack知识,包括常见的配置项,前端搭建的一些方法和项目实际优化方法,有错误的地方还请指出并多多包涵. 一.关于Webpack 1.概念 本质上,webpack ...
- Vue中router路由异步加载组件-优化性能
何时使用异步加载组件 当首页app.js文件太大时,可以拆分组件异步加载,如果app.js文件很小时,不建议使用异步加载组件,因为异步加载组件时每次都要发送一个HTTP请求,这样的代价远比首页一次性加 ...