溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2020-04-30 02:13:37 來源:網(wǎng)絡(luò) 閱讀:703 作者:mathed001 欄目:編程語言

 

  1. Private Sub CopyDir(ByVal srcPath As StringByVal aimPath As String
  2.  
  3.         Try 
  4.  
  5.             ' 檢查目標(biāo)目錄是否以目錄分割字符\結(jié)束,如果不是則添加之 
  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.             '' 判斷目標(biāo)目錄是否存在如果不存在則新建之 
  20.  
  21.             'If (Not Directory.Exists(aimPath)) Then Directory.CreateDirectory(aimPath) 
  22.  
  23.  
  24.             ' 得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組 
  25.  
  26.             Dim fileList() As String = Directory.GetFileSystemEntries(srcPath) 
  27.  
  28.             ' 遍歷所有的文件和目錄 
  29.  
  30.  
  31.             For Each FileName As String In fileList 
  32.  
  33.                 ' 先當(dāng)作目錄處理如果存在這個(gè)目錄就遞歸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 

 

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI