-
Dec 17th, 2017, 02:36 PM
#1
Thread Starter
Addicted Member
Recursive search hard drive for file types
Hello i am a bit new to vb.net i used to code in vb6 and realbasic for years but went to vb.net. I need to some help on scanning a whole hard drive for multiple with a array of file types if you guys can help me would be awesome thanks!
Code:
Public Class Form1
Public Function ListAllDrives() As String
Dim allDrives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
Dim d As IO.DriveInfo
For Each d In allDrives
Return d.Name
Next
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add(ListAllDrives)
ComboBox1.SelectedIndex = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lstResult As New List(Of String)
Dim stkStack As New Stack(Of String)
stkStack.Push(ComboBox1.text)
Do While (stkStack.Count > 0)
Dim strDirectory As String = stkStack.Pop
Try
lstResult.AddRange(IO.Directory.GetFiles(strDirectory, "*.png"))
Dim strDirectoryName As String
For Each strDirectoryName In IO.Directory.GetDirectories(strDirectory)
stkStack.Push(strDirectoryName)
Label1.Text = strDirectoryName
Next
Catch ex As UnauthorizedAccessException
MsgBox("file in use")
End Try
Loop
End Sub
End Class
-
Dec 17th, 2017, 02:50 PM
#2
Re: Recursive search hard drive for file types
Assuming your code works for .png files, simply creating an array and putting a loop around the lstResult.AddRange line should do it, eg:
Code:
stkStack.Push(ComboBox1.text)
Dim fileTypesToFind as String() = {"*.png", "*.jpg", "*.gif"}
Do While (stkStack.Count > 0)
Dim strDirectory As String = stkStack.Pop
Try
For Each fileType as String in fileTypesToFind
lstResult.AddRange(IO.Directory.GetFiles(strDirectory, fileType))
Next
Dim strDirectoryName As String
-
Dec 18th, 2017, 06:28 PM
#3
Thread Starter
Addicted Member
Re: Recursive search hard drive for file types
that code above works just the way i want how can i get folder paths like folders other then special folders want to get the windows prefetch folder any ideas what im doing wrong?
Code:
Dim Prefetch As String = (Environment.GetFolderPath("%systemroot%\prefetch"))
Last edited by sinner0636; Dec 18th, 2017 at 06:32 PM.
-
Dec 18th, 2017, 08:46 PM
#4
Thread Starter
Addicted Member
Re: Recursive search hard drive for file types
nm figured it out
Code:
Dim Prefetch As String = (Environment.GetFolderPath(Environment.SpecialFolder.Windows)) + "\Prefetch"
MsgBox(Prefetch)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|