新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
教你更快速使用VB.NET文件夾操作
文件夾這個(gè)概念大家都很熟悉,在各各操作系統(tǒng)中都有文件夾這個(gè)概念,而在VB.NET這門開發(fā)語言中如何更好更安全的操作文件夾,這就是今天我們要來演示的一個(gè)案例。希望從VB.NET文件夾操作這個(gè)案例中學(xué)到技巧。

創(chuàng)新互聯(lián)是一家專業(yè)從事成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)的網(wǎng)絡(luò)公司。作為專業(yè)網(wǎng)絡(luò)公司,創(chuàng)新互聯(lián)依托的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、成都全網(wǎng)營銷推廣及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!
VB.NET文件夾操作代碼:
- '文件夾復(fù)制
- Function CopyDir()Function CopyDir(ByVal sourcePath As String, ByVal targetPath As String) As Boolean
- Try
- '檢查目標(biāo)目錄是否以目錄分割字符結(jié)束,不是則添加
- If Right(targetPath, 1) <> "" Then targetPath += ""
- '判斷目標(biāo)目錄是否存在,不存在則新建
- If Not Directory.Exists(targetPath) Then Directory.CreateDirectory(targetPath)
- ' 得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組
- Dim fileList As String() = Directory.GetFileSystemEntries(sourcePath)
- '遍歷所有的文件和目錄
- For Each filepath As String In fileList
- '目錄處理,遞歸
- If (Directory.Exists(filepath)) Then
- CopyDir(filepath, targetPath + Path.GetFileName(filepath))
- Else
- '復(fù)制文件
- File.Copy(filepath, targetPath + Path.GetFileName(filepath), True)
- End If
- Next
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- '文件夾刪除
- Function DelDir()Function DelDir(ByVal targetPath As String) As Boolean
- Try
- '檢查目標(biāo)目錄是否以目錄分割字符結(jié)束,不是則添加
- If Right(targetPath, 1) <> "" Then targetPath += ""
- '得到源目錄的文件列表,該里面是包含文件以及目錄路徑的一個(gè)數(shù)組
- Dim fileList As String() = Directory.GetFileSystemEntries(targetPath)
- '遍歷所有的文件和目錄
- For Each filepath As String In fileList
- '目錄處理,遞歸
- If (Directory.Exists(filepath)) Then
- DelDir(targetPath + Path.GetFileName(filepath))
- Else
- '刪除文件
- File.Delete(targetPath + Path.GetFileName(filepath))
- End If
- Next
- '刪除文件夾
- System.IO.Directory.Delete(targetPath, True)
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
以上就是我為大家提高的關(guān)于VB.NET文件夾操作的一個(gè)案例,大家快試試吧!
分享題目:教你更快速使用VB.NET文件夾操作
鏈接地址:http://m.5511xx.com/article/cdcdjhg.html


咨詢
建站咨詢
