Durchsuchen aller Verzeichnisse auf der Festplatte
Hey all ich habe dieses Stück Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileSize As String = ""
Dim di As New IO.DirectoryInfo("C:\")
Try
di.GetFiles("*.*", SearchOption.AllDirectories)
Catch
End Try
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
For Each fi In aryFi
strFileSize = (Math.Round(fi.Length / 1024)).ToString()
Debug.Print("File Name: {0}", fi.Name)
'Debug.Print("File Full Name: {0}", fi.FullName)
'Debug.Print("File Size (KB): {0}", strFileSize)
'Debug.Print("File Extension: {0}", fi.Extension)
'Debug.Print("Last Accessed: {0}", fi.LastAccessTime)
Next
End Sub
und es funktioniert gut. Wenn ich das aber sage, muss ich einen Weg finden, um @ durchzuschleifALL Das Verzeichnis befindet sich auf dem Laufwerk "c" und nicht nur im Hauptordner.
Hat jemand einen Code, der das kann?
Vielen Dank
Gelöst
Imports System.IO
Imports System
Imports System.Collections.Generic
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim vFolder As String = "c:\"
WalkDirRecursive(vFolder)
End Sub
Private Sub WalkDirRecursive(ByVal vPath As String)
Dim vDirInfo As New System.IO.DirectoryInfo(vPath)
If Not vDirInfo.Exists Then Exit Sub
'get all files' sizes in current path
On Error Resume Next
For Each vFile As String In System.IO.Directory.GetFiles(vDirInfo.FullName)
'do something with this file
Debug.Print(vFile)
Next
'do the same for all subfolders
For Each vSubDir As String In System.IO.Directory.GetDirectories(vDirInfo.FullName)
WalkDirRecursive(vSubDir)
Next
End Sub
Private Sub RecurseDirectories(ByVal di As DirectoryInfo)
Try
For Each d In di.GetDirectories()
ProcessData(d)
RecurseDirectories(d)
Next
Catch
End Try
End Sub
Private Sub ProcessData(ByVal di As IO.DirectoryInfo)
Dim strFileSize As String = ""
Dim fi As IO.FileInfo
Try
di.GetFiles("*.*", SearchOption.AllDirectories)
Catch
End Try
Try
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
For Each fi In aryFi
strFileSize = (Math.Round(fi.Length / 1024)).ToString()
Debug.Print("File Name: {0}", fi.Name)
'Debug.Print("File Full Name: {0}", fi.FullName)
'Debug.Print("File Size (KB): {0}", strFileSize)
'Debug.Print("File Extension: {0}", fi.Extension)
'Debug.Print("Last Accessed: {0}", fi.LastAccessTime)
Next
Catch
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim di As New IO.DirectoryInfo("C:\")
RecurseDirectories(di)
End Sub
End Class
Davi