Exemplo n.º 1
0
    public static bool CopyDir(string fromDir, string toDir)
    {
        if (fromDir == null || toDir == null)
        {
            throw new NullReferenceException("参数为空");
        }
        if (fromDir == toDir)
        {
            throw new Exception("两个目录都是" + fromDir);
        }
        if (!Directory.Exists(fromDir))
        {
            throw new IOException("目录fromDir=" + fromDir + "不存在");
        }
        DirectoryInfo directoryInfo = new DirectoryInfo(fromDir);

        return(QFileUtils.CopyDir(directoryInfo, toDir, directoryInfo.FullName));
    }
Exemplo n.º 2
0
    private static bool CopyDir(DirectoryInfo fromDir, string toDir, string rootDir)
    {
        string text = string.Empty;

        FileInfo[] files = fromDir.GetFiles();
        for (int i = 0; i < files.Length; i++)
        {
            FileInfo fileInfo = files[i];
            text = toDir + fileInfo.FullName.Substring(rootDir.Length);
            string dirName = text.Substring(0, text.LastIndexOf("\\"));
            QFileUtils.CreateDir(dirName);
            File.Copy(fileInfo.FullName, text, true);
        }
        DirectoryInfo[] directories = fromDir.GetDirectories();
        for (int j = 0; j < directories.Length; j++)
        {
            DirectoryInfo fromDir2 = directories[j];
            QFileUtils.CopyDir(fromDir2, toDir, rootDir);
        }
        return(true);
    }
Exemplo n.º 3
0
 public static bool CopyDir(DirectoryInfo fromDir, string toDir)
 {
     return(QFileUtils.CopyDir(fromDir, toDir, fromDir.FullName));
 }