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

c#深拷貝文件夾示例

 更新時間: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)文章

最新評論

白城市| 德州市| 济宁市| 子洲县| 潼关县| 家居| 蒲城县| 吐鲁番市| 体育| 石林| 安阳县| 张家口市| 伊金霍洛旗| 日照市| 陵川县| 元谋县| 大兴区| 武功县| 玉龙| 阿拉善左旗| 崇阳县| 井研县| 屏边| 从江县| 察隅县| 永寿县| 自治县| 华蓥市| 登封市| 永吉县| 平舆县| 黎平县| 商都县| 三亚市| 堆龙德庆县| 永嘉县| 湖北省| 化州市| 衡阳县| 青海省| 巴林右旗|