Solved

Gather a Directory list into an array

Posted on 2003-10-23
5
166 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
[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
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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