最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c#深拷貝文件夾示例

 更新時(shí)間:2014年04月16日 09:47:37   作者:  
這篇文章主要介紹了c#深拷貝文件夾示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace FileUtility
{
    public class Program
    {
        public static void DeepCopy(DirectoryInfo source, DirectoryInfo target, params string[] excludePatterns)
        {
            if (target.FullName.Contains(source.FullName))
                return;

            // Go through the Directories and recursively call the DeepCopy Method for each one
            foreach (DirectoryInfo dir in source.GetDirectories())
            {
                var dirName = dir.Name;
                var shouldExclude = excludePatterns.Aggregate(false, (current, pattern) => current || Regex.Match(dirName, pattern).Success);

                if (!shouldExclude)
                    DeepCopy(dir, target.CreateSubdirectory(dir.Name), excludePatterns);
            }

            // Go ahead and copy each file to the target directory
            foreach (FileInfo file in source.GetFiles())
            {
                var fileName = file.Name;
                var shouldExclude = excludePatterns.Aggregate(false,
                                                              (current, pattern) =>
                                                              current || Regex.Match(fileName, pattern).Success);

                if (!shouldExclude)
                    file.CopyTo(Path.Combine(target.FullName, fileName));
            }
        }

        static void Main(string[] args)
        {
            DeepCopy(new DirectoryInfo(@"d:/test/b"), new DirectoryInfo(@"d:/test/a"));
            DeepCopy(new DirectoryInfo(@"d:/test/c"), new DirectoryInfo(@"d:/test/c/c.1"));
            DeepCopy(new DirectoryInfo(@"d:/test/1/"), new DirectoryInfo(@"d:/test/2/"), new string[] { ".*\\.txt" });

            Console.WriteLine("復(fù)制成功...");
            Console.ReadKey();
        }
    }
}

相關(guān)文章

最新評(píng)論

庆城县| 自贡市| 吴堡县| 永安市| 托克逊县| 海阳市| 广宁县| 府谷县| 革吉县| 金秀| 贡觉县| 深圳市| 新蔡县| 青田县| 安平县| 台南县| 安仁县| 钦州市| 蓬安县| 临清市| 蚌埠市| 右玉县| 綦江县| 井陉县| 开阳县| 陈巴尔虎旗| 介休市| 新蔡县| 黔江区| 家居| 浮梁县| 上饶县| 马尔康县| 潍坊市| 台前县| 辰溪县| 开江县| 察雅县| 西城区| 嘉峪关市| 松原市|