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 ...
随机推荐
- python中random的基本用法
那么怎么使 a 随机生成一个数值呢,来研究一下random的部分程序:python中random模块的几个函数可以随机生成数值,下面咱们看一下random的几个函数的使用方法. random()是不能 ...
- Flink入门(二)——Flink架构介绍
1.基本组件栈 了解Spark的朋友会发现Flink的架构和Spark是非常类似的,在整个软件架构体系中,同样遵循着分层的架构设计理念,在降低系统耦合度的同时,也为上层用户构建Flink应用提供了丰富 ...
- 【Python成长之路】装逼的一行代码:快速共享文件【华为云分享】
[写在前面] 有时候会与同事共享文件,正常人的操作是鼠标右键,点击共享.其实有个装逼的方法,用python的一行代码快速实现基于http服务的共享方式. [效果如下] [示例代码] 在cmd窗口进入想 ...
- 思科CISCO ASA 5521 防火墙 Ipsec 配置详解
版本信息: Cisco Adaptive Security Appliance Software Version 9.9(2) Firepower Extensible Operating Syste ...
- 洛谷 题解 P1684 考验
本蒟蒻又来发题解啦! 这个题的正解应该是贪心 直接找题目的关键: 韵脚只可能是 "AABB", "ABAB", "ABBA" 和" ...
- 三菱PLC和卓岚串口服务器使用心得
下面介绍使用FX3u-16M以及卓岚产品ZLAN5103,实现GX Works通过虚拟串口监控PLC 一.PLC通讯口 圆头8孔RS422接口,线序如下: 1.FX3u不同子型号的PLC,引脚定义可能 ...
- 学习之Redis(一)
一.redis简介 一般学习,最好先去官网,之所以建议看官网,是因为这是一手的学习资料,其他资料都最多只能算二手,一手资料意味着最权威,准确性最高.https://redis.io/topics/in ...
- 配置中心入门案例以及出现Could not resolve placeholder 'XXX' in value "${XXX}"的解决方式
编写配置中心的服务端 创建项目 修改 pom 文件添加 config-server 坐标 <?xml version="1.0" encoding="UTF-8&q ...
- hdu5969最大的位或
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5969 题意:给定自然数l和r ,选取2个整数x,y,满足l <= x <= y <= r ...
- Codeforces-527c
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...