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
Solved

Gather a Directory list into an array

Posted on 2003-10-23
5
162 Views
Last Modified: 2010-05-03
I'm lost!

Trying to retrieve a listing of files from a noted path into an array.

Any help appreciated
0
Comment
Question by:benspan
  • 2
5 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9612433
Hi!

On a form create a Command Button, and File List Box, then use this code!

Private Sub Command1_Click()
    Dim path As String
    Dim PathArray(100) As String
   
    path = "c:\"                                         'specify path
    File1 = path                                         'Set File list box to show your path

    For X = 1 To File1.ListCount
        PathArray(X) = File1.List(X - 1)          'Transfer contents of a list box to an array
    Next X

    For X = 1 To File1.ListCount
        Print PathArray(X)                              'Testing
    Next X
End Sub
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9612441
If you want to access theese files later, then you need full paths to them.

Use
             PathArray(X) = path & File1.List(X - 1)
to get full paths to files
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 50 total points
ID: 9613420
Better to use dynamic array

ie

Private Sub Command1_Click()
   Dim path As String
   Dim PathArray() As String
   
on error resume next
   path = "c:\"                                         'specify path
   File1 = path                                         'Set File list box to show your path

   For X = 1 To File1.ListCount
       i = UBound(PathArray)
        ReDim Preserve PathArray(i + 1)
       PathArray(i) = File1.List(X - 1)          'Transfer contents of a list box to an array
   Next X

   For X = 1 To File1.ListCount
       Print PathArray(X)                              'Testing
   Next X
End Sub
0
 
LVL 27

Expert Comment

by:planocz
ID: 10183455
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from benspan from 10/24/2003 comment
Award points to EDDYKT is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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