C#递归拷贝文件夹下文件以及文件夹
public bool CopyOldLabFilesToNewLab(string sourcePath, string savePath)
{
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
#region
try
{
string[] labDirs = Directory.GetDirectories(sourcePath);//目录
string[] labFiles = Directory.GetFiles(sourcePath);//文件
if (labFiles.Length > 0)
{
for (int i = 0; i < labFiles.Length; i++)
{
if (Path.GetExtension(labFiles[i]) != ".lab")
{
File.Copy(sourcePath + "\\" + Path.GetFileName(labFiles[i]), savePath + "\\" + Path.GetFileName(labFiles[i]), true);
}
}
}
if (labDirs.Length > 0)
{
for (int j = 0; j < labDirs.Length; j++)
{
Directory.GetDirectories(sourcePath + "\\" + Path.GetFileName(labDirs[j]));
//递归调用
CopyOldLabFilesToNewLab(sourcePath + "\\" + Path.GetFileName(labDirs[j]), savePath + "\\" + Path.GetFileName(labDirs[j]));
}
}
}
catch (Exception)
{
return false;
}
#endregion
return true;
}
最新文章
- bzoj1835[ZJOI2010]base基站选址
- flash 自定义右键功能
- 数往知来C#面向对象准备〈二〉
- 【转】Adobe CC 的下载地址
- ubuntu 100M 到 10M
- JAVA学习:方法
- C程序设计语言练习题1-5
- C#JSON序列化与反序列化
- Centos6.7安装chrome
- 动态SQL之、条件判断(转)
- Visual Studio 2015 插件开发入门
- Go 初体验 - 令人惊叹的语法 - defer.3 - defer 函数参数计算时机
- Android 信号处理面面观 之 信号定义、行为和来源
- 10.18号java课后作业代码
- 关于Excel分析图插入到论文的问题
- 微信支付HTTPS服务器证书验证指引
- Tomcat性能优化(三) Executor配置
- 实习培训——Java基础(4)
- 模拟form表单请求上传文件
- 错误:严重: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is