码迷,mamicode.com
首页 > 其他好文 > 详细

文件夹复制

时间:2014-10-28 11:37:28      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   sp   文件   on   cti   bs   new   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace qidi
{
    class Program
    {
        static void Main(string[] args)
        {
            CopyFolder(@"F:\C#",@"F:\dddd");         
        }

        static void CopyFolder(string sPath, string dPath)
        {
            if (!Directory.Exists(dPath))
            {
                Directory.CreateDirectory(dPath);
                DirectoryInfo sDir = new DirectoryInfo(sPath);
                FileInfo[] fileArray = sDir.GetFiles();
                foreach (FileInfo file in fileArray)
                {
                    file.CopyTo(dPath + "\\" + file.Name, true);
                }
                DirectoryInfo[] subDirArray = sDir.GetDirectories();
                foreach (DirectoryInfo subDir in subDirArray)
                {
                    CopyFolder(subDir.FullName, dPath + "//" + subDir.Name);        
                }
            }
        }  
    }
}

文件夹复制

标签:io   ar   for   sp   文件   on   cti   bs   new   

原文地址:http://www.cnblogs.com/lizhifeng/p/4056280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!