您好,登錄后才能下訂單哦!
- Private Sub CopyDir(ByVal srcPath As String, ByVal aimPath As String)
- Try
- ' 檢查目標(biāo)目錄是否以目錄分割字符\結(jié)束,如果不是則添加之
- If aimPath.Substring(aimPath.Length - 1) <> Path.DirectorySeparatorChar Then
- aimPath += Path.DirectorySeparatorChar
- End If
- '判斷源目錄是否存在,不存在則退出.
- If (Not Directory.Exists(srcPath)) Then Exit Sub
- '' 判斷目標(biāo)目錄是否存在如果不存在則新建之
- 'If (Not Directory.Exists(aimPath)) Then Directory.CreateDirectory(aimPath)
- ' 得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組
- Dim fileList() As String = Directory.GetFileSystemEntries(srcPath)
- ' 遍歷所有的文件和目錄
- For Each FileName As String In fileList
- ' 先當(dāng)作目錄處理如果存在這個(gè)目錄就遞歸Copy該目錄下面的文件
- If Directory.Exists(FileName) Then
- If (Not Directory.Exists(aimPath + Path.GetFileName(FileName))) Then Directory.CreateDirectory(aimPath + Path.GetFileName(FileName))
- CopyDir(FileName, aimPath + Path.GetFileName(FileName))
- ' 否則直接Copy文件
- Else
- File.Copy(FileName, aimPath + Path.GetFileName(FileName), True)
- End If
- Next
- Catch ex As Exception
- Response.Write("<br>" + ex.ToString())
- End Try
- End Sub
免責(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)容。