|
-
May 16th, 2011, 01:51 PM
#1
Thread Starter
New Member
Get Files From Directory
Hi,
All I want to do is get all files from a directory with a given file extension (in this case, .wav) and store the filenames in a collection. Here's what I have. I get an error for the first line in Form_Load(), "Compile error: Argument not optional", and it highlights "filenames =". Anyone know what could be wrong?
Cheers
Option Explicit
Dim filenames as New collection
-----------------------------------------------------------------
Private Sub Form_Load()
filenames = GetFiles("E:\Documents and Settings\User1\My Documents\User2\VCV\stim", "*.wav")
For c = 0 To Len(files)
Debug.Print files(c); " ";
Next c
End Sub
-----------------------------------------------------------------
' Returns a collection holding all the filenames that
' match a given filespec and search attributes.
Function GetFiles(dirname As String, filespec As String) As collection
Dim filename As String
Set GetFiles = New collection
' start the search
filename = Dir$(dirname & filespec, vbNormal)
Do While Len(filename)
' we've found a new file
GetFiles.Add filename, filename
' get ready for the next iteration
filename = Dir$
Loop
End Function
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
|