Code to loop through a directory and retreive file information

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LisaB

    Code to loop through a directory and retreive file information

    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



  • Herfried K. Wagner [MVP]

    #2
    Re: Code to loop through a directory and retreive file information

    "LisaB" <lbagley(ReTHis )@mayatech.com> schrieb:[color=blue]
    > I need help with writing the code to loop through a directory and return
    > the
    > Path, Size and Modified information for each .mdb file[/color]

    Untested (written from scratch):

    \\\
    Imports System.IO
    ..
    ..
    ..
    Dim al As New ArrayList
    SearchFiles("*. mdb", "C:\", al)
    For Each FileName As String In al
    Console.WriteLi ne(FileName)
    Console.WriteLi ne(File.GetLast AccessTime(File Name).ToString( ))
    ...
    Next FileName
    ..
    ..
    ..
    Public Sub SearchFiles( _
    ByVal Pattern As String, _
    ByVal Path As String, _
    ByVal FilesFound As ArrayList _
    )
    FilesFound.AddR ange(Directory. GetFiles(Path, Pattern))
    For Each FolderPath As String In Directory.GetDi rectories(Path)
    SearchFiles(Pat tern, FolderPath, FilesFound)
    Next FolderPath
    End Sub
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Crouchie1998

      #3
      RE: Code to loop through a directory and retreive file information

      Hi Lisa,

      The person who wrote the code is the author of Programming Microsoft Visual
      Basic .NET (ISBN: 0 - 7356 - 1375 - 3)

      Here's an example of what you need:


      Comment

      Working...