|
-
Sep 10th, 2000, 05:19 PM
#1
Thread Starter
Addicted Member
hi guys, i want to put all files under a folder into array, how do i do that???
for example
Code:
dim array(0)
for i to 0 to FileCount
array(i) = folder.file(i)
next i
i don't know if its something like this or not, but please help me,,,thanx
-
Sep 10th, 2000, 05:27 PM
#2
Here's one way of doing it:
Code:
Dim sFiles() As String
Dim sFileName As String
Const PATH = "C:\MyFolder" 'change this to whatever
Dim iFileCount As Integer
Redim sFiles(100)
sFileName = Dir(PATH & "\*.*")
Do While Len(sFileName)
sFiles(iFileCount) = sFileName
iFileCount = iFileCount + 1
If iFileCount > UBound(sFiles) Then
Redim Preserve sFiles(iFileCount + 100)
End If
sFileName = Dir
Loop
Redim Preserve sFiles(iFileCount - 1)
Good luck!
-
Sep 10th, 2000, 05:34 PM
#3
Thread Starter
Addicted Member
-
Sep 10th, 2000, 05:38 PM
#4
_______
<?>
Option Explicit
'why redim as 100....what if there were 1000 files
Code:
Private Sub Command1_Click()
'access all files within a folder
Dim stFile As String
Dim stDir As String
Dim myArr()
Dim i As Integer
stDir = "C:\Dirtbagdog\"
stFile = Dir$(stDir & "*.*")
Do While stFile <> ""
ReDim Preserve myArr(i)
myArr(i) = stFile
i = i + 1
stFile = Dir
Loop
'if you want to test it add a listbox to your form
'and run this code as well...
For i = LBound(myArr) To UBound(myArr)
List1.AddItem myArr(i)
Next i
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 10th, 2000, 05:49 PM
#5
Thread Starter
Addicted Member
-
Sep 10th, 2000, 05:51 PM
#6
Re: <?>
Originally posted by HeSaidJoe
'why redim as 100....what if there were 1000 files
Well if you have a closer look at the sample code I submitted in my previous post you will notice that I redim by the hundreds.
When the file counter (iFileCount) is higher then the UBound of the sFiles array I redim it again to be 200 (or 300 or 400 and so on).
This is because of the fact that it takes a lot or time to redim an array (and especially when you use the Preserve keyword).
In my code I only redim the array if it contains more then 100 files and I redim it again if it contains more then 200 and so on.
I then make a final redim (at the end of the code) to the array so it's not larger then it has to be.
So if the folder contains 1000 files I redim the array 10 times but in your code you do the redim 1000 times.
-
Sep 10th, 2000, 05:56 PM
#7
Thread Starter
Addicted Member
ReDim??
ok guys, a quick question, Why do we use ReDim??? and when??? and How???
-
Sep 10th, 2000, 06:01 PM
#8
You use ReDim to alter the array size. You don't know how many files there is in a specific folder so you don't know how large the array should be.
-
Sep 10th, 2000, 06:50 PM
#9
Thread Starter
Addicted Member
Thanx man
ok thanx alot man, but give me a simple example on how to use it with explaining please...
-
Sep 11th, 2000, 03:28 AM
#10
You allready have a simple example. The first post I made was an example to add all files in a directory in to an array.
This array changes in size if necassary.
-
Sep 11th, 2000, 04:33 AM
#11
Thread Starter
Addicted Member
thanx man, i havn't noticed that,,,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|