Code to loop through a directory and retreive file information

L

LisaB

I am new to Visual Basic .Net and would like to build a simple application
that searches a directory and returns the Path, Size and DateModified of all
files that end in ".MDB".

a) I would create a form to allow the user to enter the directory to be
searched - EX.. "C:\" or "D:\Program FIles" would be entered by the user

------This is the part I need Help with----------
b) The form would have a button with the following on_Click logic
-Go to the directory entered by the User (txtDirectory)
-Loop through each file in that directory and each file in any sub
directories
- If the file end in ".MDB", output it to a comma delimited text
file
- the output should have the full path and file name, the file size,
and the date last modified
----------------------------------------------------
c) some other things will also be done, but I think I can manage from here
on

I need help with writing the code to loop through a directory and return the
Path, Size and Modified information for each .mdb file

If anyone can please help or point me in the right direction I would greatly
appreciate it.

Thanks
 
H

Herfried K. Wagner [MVP]

LisaB said:
I need help with writing the code to loop through a directory and return
the
Path, Size and Modified information for each .mdb file

Untested (written from scratch):

\\\
Imports System.IO
..
..
..
Dim al As New ArrayList
SearchFiles("*.mdb", "C:\", al)
For Each FileName As String In al
Console.WriteLine(FileName)
Console.WriteLine(File.GetLastAccessTime(FileName).ToString())
...
Next FileName
..
..
..
Public Sub SearchFiles( _
ByVal Pattern As String, _
ByVal Path As String, _
ByVal FilesFound As ArrayList _
)
FilesFound.AddRange(Directory.GetFiles(Path, Pattern))
For Each FolderPath As String In Directory.GetDirectories(Path)
SearchFiles(Pattern, FolderPath, FilesFound)
Next FolderPath
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top