- A+
所属分类:vb.net
vb.net快速遍历目录和文件,包括子文件夹,
Private Sub GetAllFile(ByVal path As String)
Dim strDir As String() = System.IO.Directory.GetDirectories(path) '文件夹
Dim strFile As String() = System.IO.Directory.GetFiles(path) '文件
Dim i As Integer
'列出文件夹
' If strDir.Length > 0 Then
'For i = 0 To strDir.Length - 1
'Debug.Print(strDir(i))
' Next
' End If
If strFile.Length > 0 Then
For i = 0 To strFile.Length - 1
Debug.Print(strFile(i)) '打印到即使窗口
Next
End If
If strDir.Length > 0 Then
For i = 0 To strDir.Length - 1
Dim fs As FileInfo = New FileInfo(strDir(i))
If fs.Attributes <> 22 Then '判断系统文件夹
GetAllFile(strDir(i))
Else
MsgBox("系统文件 " & strDir(i))
End If
Next
End If
End Sub
'调用
GetAllFile("D:\")
复制