The list of files

Hello,

I have a question.

I need to receive the list of files that are placed on a given directory.
The input will be some template, for example <My*.bmp>
The output the array of strings that include file names.
It would be great to use dynamic array for storing the strings.

Thanks a lot,
John.
[345 byte] By [John _Smith] at [2007-11-15 18:34:23]
# 1 Re: The list of files
You can do the same thing using the FileSystemObject.
private Sub Command1_Click()
Dim InitPath as string, arr() as string, index as Long, FileName as string
'Change the array dimension to fit your needs.
ReDim arr(10000)
'Change the initial path to the directory you want.
InitPath = "c:\Windows\"
FileName = Dir(InitPath, vbDirectory)
index = 0
Do While FileName <> "" ' Start the loop.
If FileName <> "." And FileName <> ".." then
If Not ((GetAttr(InitPath & FileName) And vbDirectory) = vbDirectory) then
arr(index) = FileName
index = index + 1
End If
End If
FileName = Dir
Loop
ReDim Preserve arr(index - 1)
End Sub

Help us improve our answers by rating them.
MKSa at 2007-11-10 0:33:49 >
# 2 Re: The list of files
Thanks for your answer.

Do you know how it possible to filter
FileName. Because I need to choose the
files that are match to some template,
like "*.*" for example.

If it possible to return the array obtained
in this subroutine to the programm that
called it? (In other words, to transform
the subroutine to the function.) How to do it?

Thanks in advance.
John.
John _Smith at 2007-11-10 0:34:42 >
# 3 Re: The list of files
Hi,

You know I found some another solution:

private Sub GetListOfFiles(FileNameTemplate as string)

Dim i as Integer

FileList.Pattern = FileNameTemplate
FileList.Path = CurDir$

MsgBox "ListCount = " & FileList.ListCount

for i = 1 to FileList.ListCount
ListOfFiles.AddItem (FileList.List(i))
next i

End Sub

Now the question is how it possible
to set Path by using OpenFile Dialog or
somethin similar to it.

10nx,
John
John _Smith at 2007-11-10 0:35:47 >
# 4 Re: The list of files
private Sub Command1_Click()
Dim filter as string, i as Long
Dim InitPath as string, arr() as string, index as Long, FileName as string
'Change the array dimension to fit your needs.
ReDim arr(10000)
'Change the initial path to the directory you want.
InitPath = "c:\Windows\"
FileName = Dir(InitPath, vbDirectory)
index = 0
'Change the filter as needed.
filter = "*.bmp"
Do While FileName <> "" ' Start the loop.
If FileName <> "." And FileName <> ".." then
If Not ((GetAttr(InitPath & FileName) And vbDirectory) = vbDirectory) then
If (FileName Like filter) then
arr(index) = FileName
index = index + 1
End If
End If
End If
FileName = Dir
Loop
ReDim Preserve arr(index - 1)
End Sub

Help us improve our answers by rating them.
MKSa at 2007-11-10 0:36:51 >
# 5 Re: The list of files
My response to your other post 'Picture Strip' already includes some sort of file filtering (simplified though, looking only for .bmp and/or .jpg files).

here..
http://www.dev-archive.com/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=81745&page=0&view=collapsed&sb=5
aio at 2007-11-10 0:37:52 >