Solved

Gather a Directory list into an array

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

9 Experts available now in Live!

Get 1:1 Help Now