.net类库中没有直接的函数, 但可以自己写函数, 如:http://www.codeproject.com/useritems/copyDirectoriesRecursive.asp

解决方案 »

  1.   

    好像确实没有整个文件夹Copy的方法,自己写一个吧,应该不会很难的。
      

  2.   

    你先取到要复制的文件的字文件夹和文件,对文件执行复制,对文件夹循环:static void Copy(String src, String dest) {
    try{
      Directory.CreateDirectory(dest);
      String[] sub = Directory.GetDirectories(src);
      for (int i = 0; i < sub.Length; i++) {
         String name = Path.GetFileName(sub[i]);
         Copy(sub[i], dest + "\\" + name);
      }
      String[] files = Directory.GetFiles(src);
      for (int i = 0; i < files.Length; i++) {
         String name = Path.GetFileName(files[i]);
         File.Copy(files[i], dest + "\\" + name);
      }
    }catch(Exception e){
    Console.WriteLine(e);
    }
    }经过测试完全可以,但是如果出错的话,你可以加些错误处理。
      

  3.   

    http://zpcity.com/arli/commonprj/cls_DirCopy.cs
      

  4.   

    不知道C#里可不可以调API,应该是可以的吧!
    WindowsAPI里恳定有,实在不行也可以用ShellExcute()呀。
    要不就生成一个batch文件一样是可以的,这都是些懒方法,如果你愿意,当然也可以像楼上那位。
      

  5.   

    private void CopyDirectory(string sourcePath, string destPath, bool overwrite)
    {
    DirectoryInfo sourceDir = new DirectoryInfo(sourcePath);
    DirectoryInfo destDir = new DirectoryInfo(destPath); // the source directory must exist, if not raise an exception
    if (sourceDir.Exists)
    {
    // if dest dir does not exist throw an exception
    if (!destDir.Parent.Exists)
    new Exception("目的目录不存在: " + destDir.Parent.FullName, 
    new DirectoryNotFoundException()); if (!destDir.Exists) destDir.Create(); // copy all the files of the current directory
    foreach (FileInfo file in sourceDir.GetFiles())
    {
    if (overwrite)
    file.CopyTo(Path.Combine(destDir.FullName, file.Name), true);
    else
    {
    // if overwrite = false, copy the file only if it does not exist
    // this is done to avoid an IOException if a file already exists
    // this way the other files can be copied anyway...
    if (!File.Exists(Path.Combine(destDir.FullName, file.Name)))
    file.CopyTo(Path.Combine(destDir.FullName, file.Name), false);
    }
    }

    // copy all the sub-directories by recursively calling this same routine
    foreach (DirectoryInfo dir in sourceDir.GetDirectories())
    CopyDirectory(dir.FullName, Path.Combine(destDir.FullName, dir.Name), overwrite);
    }
    else
    new AppException("原目录不存在: " + sourceDir.FullName, 
    new DirectoryNotFoundException());
    }
      

  6.   

    C#里面可以system调用吗?
    system("xcopy sourcedir destdir /E /C /I /Q");