Solved

Gather a Directory list into an array

Posted on 2003-10-23
5
165 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 63
I need help embedding an image as HTML in my vb.net application 3 84
Export Data to Different .csv Files 27 131
checkbox to hide entire section 10 75
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

732 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