List File Names

I have a folder "Exports" with 400 Subfolders "Export1", "Export2" and so on. Each Export folder has 1000 TIF files. I would like to run a macro to list the First and Last File name from each folder in excel. Please see attached for a sample of what I'd like to be the output. Any help is appreciated.
Gerald sample1.xlsx
Who is Participating?
gamarrojgqConnect With a Mentor Commented:

This is the way you can do it according to you XLS example, you just need to add MICROSOFT SCRIPTING RUNTIME reference

Hope it helps
Sub GetFolderFiles()

    Dim objRange As Range
    Set objRange = ActiveSheet.Range("A2:C2")

    Dim fso As New FileSystemObject
    Dim fldrParent As Scripting.Folder
    Dim fle As Scripting.file
    Dim fldrChild As Scripting.Folder
    Dim intFileNumber As Integer
    Dim intFolder As Integer
    Dim strFirstFile As String
    Dim strLastFile As String
    Set fldrParent = fso.GetFolder("C:\Exports")
    intFolder = 0
    For Each fldrChild In fldrParent.SubFolders
        intFolder = intFolder + 1
        intFileNumber = 0
        strFirstFile = ""
        strLastFile = ""
        For Each fle In fldrChild.Files
            intFileNumber = intFileNumber + 1
            If intFileNumber = 1 Then
                strFirstFile = fle.Name
            End If
            If intFileNumber = fldrChild.Files.Count Then
                strLastFile = fle.Name
            End If
        objRange(intFolder, 1).Value = fldrChild.Name
        objRange(intFolder, 2).Value = strFirstFile
        objRange(intFolder, 3).Value = strLastFile

End Sub

Open in new window

Ardhendu SarangiSr. Project ManagerCommented:
This would be easier to do it using FolderScavenger and then in editing in excel.

First create a listing of files using folderscavenger and then you can use macros and formulas to get the result you want.

If you can create the file using FolderScavenger, then I can help do the rest of the formatting.

Let me know if you have any questions,

gparke76Author Commented:
Thanks for the response. I downloaded the free edition. It only lets me list the files one folder at a time. I was hoping to do all 400 folders in a batch process. Any ideas/suggestions?

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Ardhendu SarangiSr. Project ManagerCommented:
you can do subfolders too if I am not mistaken... let me check.
Ardhendu SarangiSr. Project ManagerCommented:
Can you try this -

Recurse folders

If selected, FolderScavenger will also recursively sweep the content of all subfolders (and their subfolders, and subfolders of subfolders, and..), and include in the files found in them in the result.
gparke76Author Commented:
Thanks for both of you. gamarrojgq's solution worked without having to do any formatting.
Thanks Again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.