RazaHasnain
asked on
filling an array with filenames
hi how do u fill a dynamic array with file names, i have this code but it fills a listbox, how do i modify this to fill an array.
And pass that array over a winsock control i.e send data.
Sub ScanDir(ByVal vsPath As String, lstList As ListBox)
'========================= ========== ========== ========== ==
'Purpose Populate a given listbox with the names of all
' files in a given directory.
'Entry vsPath - full pathname of the directory to
' search.
' lstList - the list box to populate
'Exit None, but contents of list box will have been
' modified.
'Comments One of Marks routines!
Dim sNextEntry As String
Dim iLen As Integer
Dim iAttr As Integer
'Constants for use with GetAttr():
Const ATTR_NORMAL = 0 'Normal file
Const ATTR_READONLY = 1 'Read-only file
Const ATTR_HIDDEN = 2 'Hidden file
Const ATTR_SYSTEM = 4 'System file
Const ATTR_VOLUME = 8 'Volume label
Const ATTR_DIRECTORY = 16 'MS-DOS directory
Const ATTR_ARCHIVE = 32 'File has changed since last back-up
'Define types of files etc to search for
iAttr = ATTR_NORMAL + ATTR_READONLY + ATTR_HIDDEN + ATTR_SYSTEM
'Make sure path is terminated with a \ character
iLen = Len(vsPath)
If iLen > 0 And Mid$(vsPath, iLen, 1) <> "\" Then vsPath = vsPath & "\"
'Get first entry in directory, initialises Dir()
sNextEntry = Dir(vsPath, iAttr)
'Now fetch all other entries
While Len(sNextEntry)
'Only include 'reasonable' filenames
If sNextEntry <> "." And sNextEntry <> ".." Then
lstList.AddItem sNextEntry
End If
'Fetch next filename
sNextEntry = Dir
Wend
End Sub
And pass that array over a winsock control i.e send data.
Sub ScanDir(ByVal vsPath As String, lstList As ListBox)
'=========================
'Purpose Populate a given listbox with the names of all
' files in a given directory.
'Entry vsPath - full pathname of the directory to
' search.
' lstList - the list box to populate
'Exit None, but contents of list box will have been
' modified.
'Comments One of Marks routines!
Dim sNextEntry As String
Dim iLen As Integer
Dim iAttr As Integer
'Constants for use with GetAttr():
Const ATTR_NORMAL = 0 'Normal file
Const ATTR_READONLY = 1 'Read-only file
Const ATTR_HIDDEN = 2 'Hidden file
Const ATTR_SYSTEM = 4 'System file
Const ATTR_VOLUME = 8 'Volume label
Const ATTR_DIRECTORY = 16 'MS-DOS directory
Const ATTR_ARCHIVE = 32 'File has changed since last back-up
'Define types of files etc to search for
iAttr = ATTR_NORMAL + ATTR_READONLY + ATTR_HIDDEN + ATTR_SYSTEM
'Make sure path is terminated with a \ character
iLen = Len(vsPath)
If iLen > 0 And Mid$(vsPath, iLen, 1) <> "\" Then vsPath = vsPath & "\"
'Get first entry in directory, initialises Dir()
sNextEntry = Dir(vsPath, iAttr)
'Now fetch all other entries
While Len(sNextEntry)
'Only include 'reasonable' filenames
If sNextEntry <> "." And sNextEntry <> ".." Then
lstList.AddItem sNextEntry
End If
'Fetch next filename
sNextEntry = Dir
Wend
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.