Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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

0
RazaHasnain
Asked:
RazaHasnain
1 Solution
 
Richie_SimonettiIT OperationsCommented:
dim idx as integer
dim ffiles() as string
'Now fetch all other entries
While Len(sNextEntry)

   'Only include 'reasonable' filenames
   If sNextEntry <> "." And sNextEntry <> ".." Then
       redim preserve ffiles(idx)
       ffiles(idx)= sNextEntry
       idx=idx+1
   End If

   'Fetch next filename
   sNextEntry = Dir
Wend

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now