My.Class.IO.DirOperate.CopyDir(string strFromDirectory, string strToDirectory)

public bool CopyDir(string strFromDirectory, string strToDirectory)
{
    Directory.CreateDirectory(strToDirectory);

    if (!Directory.Exists(strFromDirectory)) return false;

    string[] directories = Directory.GetDirectories(strFromDirectory);

    if (directories.Length > 0)
    {
        foreach (string d in directories)
        {
            CopyDir(d, strToDirectory + d.Substring(d.LastIndexOf("\\")));
        }
    }
    string[] files = Directory.GetFiles(strFromDirectory);

    if (files.Length > 0)
    {
        foreach (string s in files)
        {
            File.Copy(s, strToDirectory + s.Substring(s.LastIndexOf("\\")));
        }
    }
    return true;
}

posted @ 2010-08-26 17:36  Aaron Xu  阅读(182)  评论(0编辑  收藏  举报