LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default ListDir

I have some code that will list all the files in a particular folder. Is
there a way to do the same with just the names of folders in a directory?

Sub ListDir()
Dim i As Long
LocDir = InputBox("Copy & paste the directory you need to have listed.")
With Application.FileSearch
.NewSearch
.LookIn = LocDir
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortByFileName) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 2).Value = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

Columns("B:B").Select
Selection.Replace What:=LocDir, Replacement:="" _
, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="\", Replacement:="" _
, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

Range("A1").Select

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"