VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "FileSystemScanner" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False ' builds a list of files in a directory with a specific extension Dim pathParts(30) As String Dim pathPartsIndex As Integer Public Function ScanFor(f As String, ext As String) Dim row As Integer pathPartsIndex = 0 row = bflotFolder(f, ext, 1) ScanFor = 1 End Function Private Function bflotFolder(folder As String, ext As String, row As Integer) As Integer Dim fs, f, f1, fc, s Dim newName As String Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folder) Set Files = f.Files pathParts(pathPartsIndex) = f.Name pathPartsIndex = pathPartsIndex + 1 newName = "" For Each File In Files If (File.Name Like "*" & ext) Then Worksheets("Sheet1").Cells(row, 1).Value = File.Path newName = File.Name newName = Left$(newName, (Len(newName) - Len(ext))) Worksheets("Sheet1").Cells(row, 2).Value = row & "_" & pathParts(1) & "_" & newName & ".txt" row = row + 1 End If Next Set fc = f.SubFolders For Each subFolder In fc If (subFolder.Attributes And 1) Then ' nothing Else row = bflotFolder(subFolder.Path, ext, row) End If Next pathPartsIndex = pathPartsIndex - 1 bflotFolder = row End Function