成都创新互联网站制作重庆分公司

文件夹及其子文件夹CopyVB.NET

  1. Private Sub CopyDir(ByVal srcPath As String, ByVal 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("
    " + ex.ToString()) 
  55.  
  56.         End Try 
  57.  
  58.     End Sub 

 

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了利辛免费建站欢迎大家使用!


当前文章:文件夹及其子文件夹CopyVB.NET
网站路径:http://cxhlcq.com/article/gjhshs.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部