?
Solved

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

Posted on 2003-03-20
3
Medium Priority
?
159 Views
Last Modified: 2010-04-07
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
Comment
Question by:franknasr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8173725
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
 
LVL 18

Accepted Solution

by:
deighton earned 340 total points
ID: 8173957
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
 

Author Comment

by:franknasr
ID: 8176199
This was perfect thank you very much.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question