文件Copy和文件夹Copy
文件Copy和文件夹Copy
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//源目录
string sourceDirectory = @"E:\\Program"; //目标目录
string destDirectory = @"E:\\Test";
//拷贝目录
copyDirectory(sourceDirectory, destDirectory);
Console.WriteLine("拷贝完毕");
Console.ReadLine();
}
public static void copyDirectory(string sourceDirectory, string destDirectory)
{
//判断源目录和目标目录是否存在,如果不存在,则创建一个目录
if (!Directory.Exists(sourceDirectory))
{
Directory.CreateDirectory(sourceDirectory);
}
if (!Directory.Exists(destDirectory))
{
Directory.CreateDirectory(destDirectory);
}
//拷贝文件
copyFile(sourceDirectory, destDirectory); //拷贝子目录
//获取所有子目录名称
string[] directionName = Directory.GetDirectories(sourceDirectory); foreach (string directionPath in directionName)
{
//根据每个子目录名称生成对应的目标子目录名称
string directionPathTemp = destDirectory + "\\" + directionPath.Substring(sourceDirectory.Length + ); //递归下去
copyDirectory(directionPath, directionPathTemp);
}
}
public static void copyFile(string sourceDirectory, string destDirectory)
{
//获取所有文件名称
string[] fileName = Directory.GetFiles(sourceDirectory); foreach (string filePath in fileName)
{
//根据每个文件名称生成对应的目标文件名称
string filePathTemp = destDirectory + "\\" + filePath.Substring(sourceDirectory.Length + ); //若不存在,直接复制文件;若存在,覆盖复制
if (File.Exists(filePathTemp))
{
File.Copy(filePath, filePathTemp, true);
}
else
{
File.Copy(filePath, filePathTemp);
}
}
}
}
}
文件Copy和文件夹Copy的更多相关文章
- Java 实现文件上传、下载、打包、文件copy、文件夹copy。
文件and文件夹copy package org.test; import java.io.*; public class FileCopy { /** * 复制单个文件 * * @param old ...
- c# 复制整个文件夹的内容,Copy所有文件
/// <summary> /// 文件夹下所有内容copy /// </summary> /// <param name="SourcePath"& ...
- iOS开发文件夹--Copy items if needed
蓝色文件夹 蓝色文件夹(folder)一般作为资源文件夹使用,与黄色文件夹的主要区别是不参与编译,所以说如果你在这些文件夹下编写的逻辑代码是不参与编译的,其他文件也不能直接引用它们,若引用其中文件需要 ...
- 多任务案例--文件夹copy.py
import os import multiprocessing def copy_file(q,file_name,new_folder_name,old_folder_name): with op ...
- cmd copy命令 文件复制【转】
本文转载自:https://www.jb51.net/article/18981.htm copy,中文含义为“复制”,一个很容易见名知意的命令,它的作用是复制文件,用法十分简单:copy 源文件 目 ...
- 工作总结 1 sql写法 insert into select from 2 vs中 obj文件和bin文件 3 npoi 模板copy CopySheet 最好先全部Copy完后 再根据生成sheet写数据 4 sheet.CopyRow(rowsindex, rowsindex + x); 5 npoi 复制模板如果出现单元格显示问题
我们可以从一个表中复制所有的列插入到另一个已存在的表中: INSERT INTO table2SELECT * FROM table1; 或者我们可以只复制希望的列插入到另一个已存在的表中: INSE ...
- Roslyn 如何使用 MSBuild Copy 复制文件
本文告诉大家如何在 MSBuild 里使用 Copy 复制文件 需要知道 Rosyln 是 MSBuild 的 dotnet core 版本. 在 MSBuild 里可以使用很多命令,本文告诉大家如何 ...
- Python [习题] 文件操作:目录间copy 文件
[习题] 指定一个源文件,实现copy到目标目录.例如把/tmp/sample1.txt 拷贝到/tmp/sample2.txt原文件需要有读权限(默认rt权限),目标文件需要给写(w即可)权限. I ...
- C# 文件copy和文件删除
C# 文件copy和文件删除 public bool CopyFile(string SourcePath, string CopyPathFoder) { bool bfg = false; if ...
随机推荐
- 5 款傻瓜式手机 APP 开发工具
http://www.oschina.net/news/21552/5-app-creators
- LAMT基于mod_proxy方式的负载均衡集群
一.apache服务器 # httpd -D DUMP_MODULES | grep proxy查看是否有 proxy_balancer_module (shared)模块 二.编辑配置文件 1.编 ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- HDU-4003 Find Metal Mineral (树形DP+分组背包)
题目大意:用m个机器人去遍历有n个节点的有根树,边权代表一个机器人通过这条边的代价,求最小代价. 题目分析:定义状态dp(root,k)表示最终遍历完成后以root为根节点的子树中有k个机器人时产生的 ...
- 越狱Season 1-Episode 19: The Key
Season 1, Episode 19: The Key -Kellerman: WeusedtohaveaGreatDane, Dane: 丹麦大狗 我们以前有一只大丹犬 bigandwild. ...
- 使用jquery插件实现图片延迟加载技术(懒加载)
有时我们看到一些大型网站,页面如果有很多图片的时候,当你滚动到相应的行时,当前行的图片才即时加载的,这样子的话页面在打开只加可视区域的图片,而其它隐藏的图片则不加载,一定程序上加快了页面加载的速度,对 ...
- 二十四种设计模式:原型模式(Prototype Pattern)
原型模式(Prototype Pattern) 介绍用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象.示例有一个Message实体类,现在要克隆它. MessageModel usin ...
- Oracle数据库查询语句
编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据: 1.列出至少有一个员工的所有部门. SQL语句: select * from SCOTT.DEPT where dept ...
- 动态进行JQ Validate 的方法
$.validator.unobtrusive.parse($('form[action = "@Url.Action()"]'));
- OSI安全体系结构
建立七层模型主要是为解决异种网络互连时所遇到的兼容性问题.它的最大优点是将服务.接口和协议这三个概念明确地区分开来;也使网络的不同功能模块分担起 不同的职责.也就是说初衷在于解决兼容性,但当网络发展到 ...