文件夹及其子文件夹Copy VB.NET

发布时间:2020-04-30 02:13:37 作者:mathed001
来源:网络 阅读:700

 

  1. Private Sub CopyDir(ByVal srcPath As StringByVal aimPath As String
  2.  
  3.         Try 
  4.  
  5.             ' 检查目标目录是否以目录分割字符\结束,如果不是则添加之 
  6.  
  7.             If aimPath.Substring(aimPath.Length - 1) <> Path.DirectorySeparatorChar Then 
  8.  
  9.                 aimPath += Path.DirectorySeparatorChar 
  10.  
  11.             End If 
  12.  
  13.  
  14.             '判断源目录是否存在,不存在则退出. 
  15.  
  16.             If (Not Directory.Exists(srcPath)) Then Exit Sub 
  17.  
  18.  
  19.             '' 判断目标目录是否存在如果不存在则新建之 
  20.  
  21.             'If (Not Directory.Exists(aimPath)) Then Directory.CreateDirectory(aimPath) 
  22.  
  23.  
  24.             ' 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组 
  25.  
  26.             Dim fileList() As String = Directory.GetFileSystemEntries(srcPath) 
  27.  
  28.             ' 遍历所有的文件和目录 
  29.  
  30.  
  31.             For Each FileName As String In fileList 
  32.  
  33.                 ' 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 
  34.  
  35.                 If Directory.Exists(FileName) Then 
  36.  
  37.                     If (Not Directory.Exists(aimPath + Path.GetFileName(FileName))) Then Directory.CreateDirectory(aimPath + Path.GetFileName(FileName)) 
  38.  
  39.                     CopyDir(FileName, aimPath + Path.GetFileName(FileName)) 
  40.  
  41.                     ' 否则直接Copy文件 
  42.  
  43.                 Else 
  44.  
  45.                     File.Copy(FileName, aimPath + Path.GetFileName(FileName), True
  46.  
  47.                 End If 
  48.  
  49.             Next 
  50.  
  51.  
  52.         Catch ex As Exception 
  53.  
  54.             Response.Write("<br>" + ex.ToString()) 
  55.  
  56.         End Try 
  57.  
  58.     End Sub 

 

推荐阅读:
  1. .NET项目修改文件夹
  2. ASP.NET 获取文件夹内所有文件及文件夹列表

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

职场 文件夹 拷贝

上一篇:百度地图API-调用后台接口画出点位

下一篇:zabbix对Windows server的监控

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》