Aquiring Directory names

A

aking1987

Works great, except it comes back with subfolders...

3 Folders named EG1, EG2, and EG3, site in location...

X:/EXAMPLE/EXAMPLE/

there are furthur subfolders within eg1, eg2, and eg3.

how can i adjust this so the ONLY list that is displayed on th
worksheet is the original folder names... EG1, EG2, EG3

(obviously EG1,2,3 will change)

Is it possible to mask the location too?

As in all that shows in the sheet (folders) will be EG1,EG2, an
EG3...

no p:/EXAMPLE/EXAMPLE/

MANY THANKS AGAIN!

Antoni
 
B

Bob Phillips

Sod's law. Most people want sub-folders as well <vbg>

Try this

Dim FSO As Object
Dim cnt As Long
Dim arfiles

Sub Folders()
Dim i As Long
Dim sFolder As String
Dim Folder As Object
Dim fldr As Object

Set FSO = CreateObject("Scripting.FileSystemObject")

arfiles = Array()
cnt = 0

sFolder = "C:\myTest"
ReDim arfiles(1)
If sFolder <> "" Then

Set Folder = FSO.GetFolder(sFolder)
For Each fldr In Folder.Subfolders
ReDim Preserve arfiles(cnt)
arfiles(cnt) = fldr.Path
cnt = cnt + 1
Next

Worksheets.Add.Name = "Folders"
With ActiveSheet
For i = LBound(arfiles) To UBound(arfiles)
.Cells(i + 1, 1) = arfiles(i)
Next
.Columns("A:Z").EntireColumn.AutoFit
End With
End If

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top