• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

How do I get an array of file names from a directory

I have a directory on a server that contains over 40000 files and I need an array to contain the names of all of these files so that I can then do something with them. I was wondering if there was a nice VB tool that could do this for me.

My original thought was to use a file list box and then sequentially grab the names of each file and write them to the array but I discovered that file list boxes cannot handle this many files so I am at a loss.

Thank you for any help you can offer me.


0
franknasr
Asked:
franknasr
1 Solution
 
Richie_SimonettiIT OperationsCommented:
sub ListFiles(sPath as string)
dim arr() as string,ff as string
dim l as long

ff=dir$(sPath & "\*.*", vbarchive)
do while ff<>""
    redim preserve arr(l)
    arr(l)= sPath & "\" & ff
    l=l+1
ff=dir$()
loop
0
 
deightonCommented:
An array of 40,000 strings will create an overhead on your pc - since the data is already there, why not use the file scripting object to give you the file names one at a time.

make a referenct to scrrun.dll


Option Explicit

Private Sub Form_Load()

ListFiles "c:\download"


End Sub

Private Sub ListFiles(spath As String)


Dim fso As New FileSystemObject
Dim fil As File

For Each fil In fso.GetFolder(spath).Files

    'work on the files here

    Debug.Print fil.Name
Next

Set fso = Nothing

End Sub
0
 
franknasrAuthor Commented:
This was perfect thank you very much.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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