Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Folder and Place Folder Names in Excel

Status
Not open for further replies.

Mantle51

Programmer
Aug 17, 2006
97
US
Hi,

I have the following that places all file names in a folder into a sheet, however I want the folder names within a folder placed into the sheet. Is this possible?

NextRow = 2
With Application.FileSearch
.NewSearch
.LookIn = "W:\Compliance2\2 - Account Approval Process\2 - CORPORATE CLIENTS"
.Filename = "*.*"
.Execute

FileToProcess = .FoundFiles.Count

For i = 1 To .FoundFiles.Count
ThisEntry = .FoundFiles(i)
Cells(NextRow, 1).Value = ThisEntry

NextRow = NextRow + 1

Next i
 
Mantle51,
I would stick with the [tt]FileSearch[/tt] object since it's faster.

If you want to search sub-folders in the [tt]LookIn[/tt] path just add the following to your routine:
Code:
With Application.FileSearch
...
  .SearchSubFolders = True
...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I thought the OP wanted subfolder names, not names in subfolders ...
 
PHV,
I'm not sure from the post since the [tt]FileSearch[/tt] object returns the complete path and name of a file.

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top