Results 1 to 7 of 7

Scan Through All Files and Subdirectories

Threaded View

  1. #1
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208

    Scan Through All Files and Subdirectories

    Hi everyone.

    I am trying to scan through all files within a directory and all subdirectories to find files where the name begins with certain characters. Below is code that will accomplish this for a certain directory, but I do not know how to look through the subdirectories within the specified directory. So, the issues are:

    1. How do I loop through each subdirectory within a specified directory?

    2. I am trying to return the file name, path name (separate from the file name), and modified date. I can return the name. I can return the path, but it includes the name. Is there a way to return just the path?

    3. What is the code to return the modified date of the file?

    Thanks in advance for any help.

    Jason

    Sub Scan_Files()
    
        Dim Fso, Fs, Fl
        Dim FolderSpec As String
        Dim i As Integer
        
    'set directory:
        FolderSpec = "\\Server\Files\"
        i = 0
        
        Set Fso = CreateObject("Scripting.FileSystemObject")
        Set Fs = Fso.GetFolder(FolderSpec)
        
        For Each Fl In Fs.Files
            If UCase(Left(Fl.Name, 4)) = "A323" Then
                Cells(Range("StartHere").Row + i, Range("StartHere").Column) = Fl.Name
                Cells(Range("StartHere").Row + i, Range("StartHere").Column + 1) = Fl.Path
                i = i + 1
            End If
        Next Fl
    
    End Sub
    Last edited by jasoncw; 01-06-2009 at 11:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1