Solved

List File Names

Posted on 2011-03-04
6
295 Views
Last Modified: 2012-05-11
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.
Thanks
Gerald sample1.xlsx
0
Comment
Question by:gparke76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 35039785
HI,
This would be easier to do it using FolderScavenger and then in editing in excel.

http://www.folderscavenger.com/

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,

Thanks,
Ardhendu
0
 

Author Comment

by:gparke76
ID: 35040047
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?

Thanks
0
 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 35040091
you can do subfolders too if I am not mistaken... let me check.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 20

Expert Comment

by:Ardhendu Sarangi
ID: 35040114
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.

http://goo.gl/7JW6H
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35040131
Hi,

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
        Next
          
        objRange(intFolder, 1).Value = fldrChild.Name
        objRange(intFolder, 2).Value = strFirstFile
        objRange(intFolder, 3).Value = strLastFile
          
    Next

End Sub

Open in new window

0
 

Author Comment

by:gparke76
ID: 35040334
Thanks for both of you. gamarrojgq's solution worked without having to do any formatting.
Thanks Again.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question