您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> C语言 >> 辅导 >> 正文    
  c#实现复制全部文件夹和文件代码 【注册男护士专用博客】          

c#实现复制全部文件夹和文件代码

www.nanhushi.com     佚名   不详 

  代码如下:
  private void Copy()
  {
  System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("D:\\data");
  CopyDirectorysAndFiles("c:\\", dir);
  }
  private void CopyDirectorysAndFiles(string dest, System.IO.DirectoryInfo srcdir)
  {
  if (dest.LastIndexOf('\\') != (dest.Length - 1))
  {
  dest += "\\";
  }
  string destPath = dest + srcdir.Name + "\\";
  if (!System.IO.Directory.Exists(destPath))
  {/Examda/
  System.IO.Directory.CreateDirectory(destPath);
  }
  System.IO.FileInfo[] files = srcdir.GetFiles();
  foreach (System.IO.FileInfo file in files)
  {
  file.CopyTo(destPath+file.Name , true);
  }
  System.IO.DirectoryInfo[] dirs = srcdir.GetDirectories();
  foreach (System.IO.DirectoryInfo dirInfo in dirs)
  {
  CopyDirectorysAndFiles(destPath , dirInfo);
  }
  }

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目