您的位置:首页 > 编程语言 > C#

[转]C# 实现对文件夹及其子文件夹的整体复制

2009-08-08 17:48 441 查看
Code
1 private void CopyFiles(string strSouPath, string strDesPath)
2 {
3 Directory.CreateDirectory(strDesPath);
4
5 if (!Directory.Exists(strSouPath)) return;
6
7 string[] directories = Directory.GetDirectories(strSouPath);
8
9 if (directories.Length > 0)
10 {
11 foreach (string d in directories)
12 {
13 CopyFiles(d, strDesPath + d.Substring(d.LastIndexOf("\\")));
14 }
15 }
16
17 string[] files = Directory.GetFiles(strSouPath);
18
19 if (files.Length > 0)
20 {
21 foreach (string s in files)
22 {
23 File.Copy(s, strDesPath + s.Substring(s.LastIndexOf("\\")));
24 }
25 }
26 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐