Hi all,

Inside the path C:\Users\user\Documents\Test Searcher I have a lot of folders that have the material and the customer name as a part of the folder string name:

3154- Shoes Puma
3155- Shirt Puma
3156- Shoes Adidas
3157- Belt Nike

etc...

Inside these folders then there are still more subfolders with a lot of files. Also note that there are More than 3000 folders....

My goal was to achieve a Macro to list all the files that the name of the file contains the specific text I would put in A2 through all the subfolders from the main folders that contains part of the text I would put in A1.

Ex: From all the folders inside the path C:\Users\user\Documents\Test Searcher that for example contains the words "Shoes" to then search inside all the subfolders of that specific folders all the files containing the file name text "template"

So, in A2 would appear part of the file name "Template" and in A1 part of the folder name "Shoes".

Because I'm quite a begginer, the closest code I could achieve is the one created by Akatrouble based on this thread https://www.excelforum.com/excel-pro...ple-paths.html I edited the code to achieve the following:

Based on the folder (and all the subfolders) from the path I put in A1 to look for all the files that contains in the file name the text I put in A2 and make a list to be pasted in the sheet named "Test Searcher"

'Force the explicit delcaration of variables
Option Explicit
Sub ListFiles()
    'Set a reference to Microsoft Scripting Runtime by using
    'Tools > References in the Visual Basic Editor (Alt+F11)
    
    'Declare the variables
    Dim objFSO As Scripting.FileSystemObject
    Dim objTopFolder As Scripting.Folder
    Dim strTopFolderName As String
   


    'Assign the folder to analize:
    strTopFolderName = Range("A1")

    
    ' create a new sheet
    'ThisWorkbook.Sheets.Add(after:=Sheets(Sheets.Count)).Name = Mid$(strTopFolderName, InStrRev(strTopFolderName, "\") + 1)
    'Paste in the existing sheet:
    Sheets("Test Searcher").Select
    
    'Insert the headers for Columns A through F
    Range("A1").Value = "File Name"
    Range("B1").Value = "File Size"
    Range("C1").Value = "File Type"
    Range("D1").Value = "Date Created"
    Range("E1").Value = "Date Last Accessed"
    Range("F1").Value = "Date Last Modified"
    Range("G1").Value = "File Path"
    
    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Get the top folder
    Set objTopFolder = objFSO.GetFolder(strTopFolderName)
    
    'Call the RecursiveFolder routine
    Call RecursiveFolder(objTopFolder, True)
    
    'Change the width of the columns to achieve the best fit
    Columns.AutoFit
   
    
End Sub

Sub RecursiveFolder(objFolder As Scripting.Folder, _
    IncludeSubFolders As Boolean)

    'Declare the variables
    Dim objFile As Scripting.File
    Dim objSubFolder As Scripting.Folder
    Dim NextRow As Long
    
    'Find the next available row
    NextRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    'Loop through each file in the folder
    For Each objFile In objFolder.Files
    If InStr(objFile.Name, Worksheets("Sheet1").Range("A2").Value) Then
        Cells(NextRow, "A").Value = objFile.Name
        Cells(NextRow, "B").Value = Format(objFile.Size, "0,000") & " KB"
        Cells(NextRow, "C").Value = objFile.Type
        Cells(NextRow, "D").Value = objFile.DateCreated
        Cells(NextRow, "E").Value = objFile.DateLastAccessed
        Cells(NextRow, "F").Value = objFile.DateLastModified
        Cells(NextRow, "G").Value = objFile.Path
        NextRow = NextRow + 1
        End If
    Next objFile
    
    'Loop through files in the subfolders
    If IncludeSubFolders Then
        For Each objSubFolder In objFolder.SubFolders
            Call RecursiveFolder(objSubFolder, True)
        Next objSubFolder
    End If
    
End Sub
Although it is not exactly what I want, I still could work with it. The code works good, but I'm the dealing with a small issue that I certainly don't know how to solve. For some reason the part from this code is case sensitive:

    If InStr(objFile.Name, Worksheets("Sheet1").Range("A2").Value) Then
        Cells(NextRow, "A").Value = objFile.Name
meaning if I put in range A2 the text "plate" it will list all the files that have the name "Template" for example. But if in A2 I put "PLATE" or "TEMPLATE" it will not list any file if the file name is written as "Template". I've tried to use Lcase function, but because I have some different text possibilites it fails to work in some cases. So my will would be to list all the files without taking into account any capitalization, therefore as a total case insensitive.

Is there any way to achieve that? Or I should create a completly new code?

Thanks in advance for your kind attention!