dir() function & listbox
is there a way to use the dir() function and load the filenames in the selected directory into a list box?
if not, how can this be done??
[146 byte] By [
rockinron] at [2007-11-15 18:34:46]

# 1 Re: dir() function & listbox
option Explicit
'Add a commandbutton and a list box to a form
private Sub Command1_Click()
Dim InitPath as string, arr() as string, index as Long, FileName as string
'Change the array dimension to fit your needs.
ReDim arr(10000)
'Change the initial path to the directory you want.
InitPath = "c:\Windows\"
FileName = Dir(InitPath, vbDirectory)
index = 0
Do While FileName <> "" ' Start the loop.
If FileName <> "." And FileName <> ".." then
If Not ((GetAttr(InitPath & FileName) And vbDirectory) = vbDirectory) then
arr(index) = FileName
List1.AddItem FileName
index = index + 1
End If
End If
FileName = Dir
Loop
ReDim Preserve arr(index - 1)
End Sub
Help us improve our answers by rating them.
MKSa at 2007-11-10 0:33:47 >
