惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
Google DeepMind News
Google DeepMind News
U
Unit 42
博客园 - 叶小钗
博客园 - 聂微东
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
美团技术团队
The Cloudflare Blog
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
S
Schneier on Security
C
Check Point Blog
Project Zero
Project Zero
The Hacker News
The Hacker News
Scott Helme
Scott Helme
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cisco Talos Blog
Cisco Talos Blog
P
Privacy International News Feed
SecWiki News
SecWiki News
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
H
Help Net Security
TaoSecurity Blog
TaoSecurity Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Last Week in AI
Last Week in AI
P
Privacy & Cybersecurity Law Blog
Forbes - Security
Forbes - Security
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity
A
About on SuperTechFans
T
The Exploit Database - CXSecurity.com
C
Cisco Blogs
PCI Perspectives
PCI Perspectives
大猫的无限游戏
大猫的无限游戏
T
Troy Hunt's Blog
H
Hacker News: Front Page
Vercel News
Vercel News

博客园 - zhengfeng

GridView 72般绝技 链接打开固定大小的新窗口 iframe传值和自适应高度 页面传参 小技巧 js表单验证控制代码大全 - zhengfeng - 博客园 递归写的复制文件夹及其下的内容(原样复制) JS取得URL中的参数值 自己写的将文件从多个文件合并到一个文件夹的小方法 使用 Hashtable 集合(一) MessageBox.Show用法 System.IO.File类和System.IO.FileInfo类 Math.floor和Math.ceil函数 Document对象 javascript小技巧 JavaScript的学习 正则表达式的学习: 工作小结: DataList分页
自己写的递归方法复制文件夹里面的内容(从源文件(里面可以有多个层次的子文件夹)到一个文件夹)
zhengfeng · 2007-07-23 · via 博客园 - zhengfeng

 private void CopyFile(string source, string destination)
        {
                bool flag = true;
                if (!Directory.Exists(destination) && flag == true)
                {
                    Directory.CreateDirectory(destination);
                    flag = false;
                }
                DirectoryInfo rootdir = new DirectoryInfo(source);

                //遍历文件  
                FileInfo[] fileinfo = rootdir.GetFiles();
                foreach (FileInfo file in fileinfo)
                {
                    file.CopyTo(destination + "\\" + file.Name, true);
                }
                DirectoryInfo[] childdir = rootdir.GetDirectories();
                for (int i = 0; i < childdir.Length; i++)
                {
                    try
                    {
                        FileInfo[] fileinfo_child = childdir[i].GetFiles();
                        foreach (FileInfo file_child in fileinfo_child)
                        {
                            file_child.CopyTo(destination + "\\" + file_child.Name, true);
                        }
                        //递归方法
                        DirectoryInfo[] childdir_child = childdir[i].GetDirectories();
                        if (childdir_child.Length > 0)
                        {
                            for (int j = 0; j < childdir_child.Length; j++)
                            {
                                CopyFile(source + "\\" + childdir[i].Name + "\\" + childdir_child[j].Name, destination);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        continue;
                    }
                }
          } 
--------------------------------------------------------------
另外一种方法:
  // 复制合并图片到一个文件夹
        static void CopyPicToFileDirectory()
        {
            Console.WriteLine("请输入源文件夹路径:");
            string sPath = Console.ReadLine();
            if (!Directory.Exists(sPath))
            {
                Console.WriteLine("源文件夹路径不存在!");
                return;
            }

            Console.WriteLine("请输入目标文件夹路径:");
            string dPath = Console.ReadLine();
            if (!Directory.Exists(dPath))
            {
                Console.WriteLine("目标文件夹路径不存在!");
                return;
            }
           
           
            Console.WriteLine("是否删除原文件:Press [Y]/[N]");
            bool isMove = false;
            string str1 = null;
            str1 = Console.ReadLine();
            bool flag = (str1 == null)?false:true;
            while (flag)
            {
                if ("y".Equals(str1.Trim().ToLower()))
                {
                    //yes
                    isMove = true;
                    break;
                }
                else if ("n".Equals(str1.Trim().ToLower()))
                {
                    //no
                    isMove = false;
                    break;
                }
                Console.WriteLine("是否删除原文件:Press [Y]/[N]");
                str1 = Console.ReadLine();
                flag = (str1 == null) ? false : true;
            }

            DoCopyFile(sPath, dPath, isMove);
        }

        private static void DoCopyFile(string sPath, string dPath, bool isMove)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(sPath);
            string destionFilename = null;
            FileInfo[] fileInfos = directoryInfo.GetFiles();
            foreach (FileInfo f in fileInfos)
            {
                destionFilename = dPath.Trim('\\') + "\\" + f.Name;
                f.CopyTo(destionFilename, true);
                if (isMove)
                {
                    f.Delete();
                }
            }
            DirectoryInfo[] subDirectories = directoryInfo.GetDirectories();
            foreach (DirectoryInfo d in subDirectories)
            {
                DoCopyFile(d.FullName, dPath, isMove);
            }
        }