Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 14,951 times

Related Categories

Creating Folder/File lists Recursively - Introduction

Kimmy

Introduction

This routine will search a folder and its subfolders and generate a list of files/folders.

just do something like: RecurseFiles "C:\Windows"

You need List1, a Listbox. or change it to do whatever you want with the names.

Sub RecurseFiles(fPath As String)
    Dim File_Name As String
    Dim File_Path As String
    Dim File_Read As Integer
    Dim x As Boolean
    Dim i As Integer

    File_Path = fPath
    If Right$(fPath, 1) <> "\" Then File_Path = fPath & "\"
   
    File_Name = Dir$(File_Path, vbDirectory)
    File_Read = 1
    x = False

    Do While File_Name <> ""
        If File_Name <> "." And File_Name <> ".." Then
            strtpath$ = File_Path & File_Name
            x = True

            If GetAttr(strtpath) And vbDirectory Then
                ' Create a list of files/folders in this subfolder
                RecurseFiles strtpath$
            Else
                ' just add the files and subfolders name not the rootname$
                ' to the list
                'ie: "c:\Windows\temp" would be "temp"
                List1.AddItem Mid$(strtpath$, Len(Dir1.Path) + 2)
            End If
        End If
       
        If x = True Then
            File_Name = Dir$(File_Path, vbDirectory)
            For i = 2 To File_Read
                File_Name = Dir$
            Next
            x = False
        End If
       
        File_Name = Dir$
        File_Read = File_Read + 1
    Loop
End Sub

Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.

Comments

  • list Files and folders recursively

    Posted by love2rules on 13 Apr 2005

    Hey all

    I have more like of a question than comment!!!

    I have never programmed using VB is there any way to get program of this function...I need to list files and folders in a particular direct...