Solved

Gather a Directory list into an array

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 65
Excel object stays open 19 71
How to debug this code 7 56
Using an encrypted  value to decrypt and display contents in vb6 9 50
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now