龙之家园  
我的博客我做主!

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Program manger = new Program();
            manger.CopyPicToFileDirectory("E:\\资讯抓取\\Images", "E:\\资讯抓取\\图片");
        }
        private void CopyPicToFileDirectory(string sourcePath, string desPath)
        {
         
                string[] dirs1 = null;
                string[] dirs2 = null;
                bool desFileDirectory = System.IO.Directory.Exists(desPath);
                if (desFileDirectory == false)
                {
                    Directory.CreateDirectory(desPath);
                }
                dirs1 = Directory.GetDirectories(sourcePath);
                for (int i = 0; i < dirs1.Length; i++)
                {
                    try
                    {
                        dirs2 = Directory.GetFiles(dirs1[i]);
                        for (int j = 0; j < dirs2.Length; j++)
                        {
                            FileInfo file = new FileInfo(dirs2[j]);
                            string filename = file.Name;
                            file.CopyTo(desPath + "\\" + filename, true);
                        }
                    }
                  catch (Exception ex)
                  {
                      Console.Write(ex.Message);
                      continue;
                  }
                }
          }
      

    }
}

posted on 2007-07-20 11:29  zhengfeng  阅读(630)  评论(0编辑  收藏  举报