Jan. 10, 2005
I was working on this as the others were posting! :) It's nice to get
lots of replies! Try:
public sub button1_click(...) ...
dim files as arraylist
dim exts() as string = {"*.txt", "*.rtf"}
arr = GetFiles(exts)
' Do something with arr
end sub
Public Function GetFiles(byval ext() as string) as ArrayList
dim Files as new arraylist
dim extension as string
dim dir as new directoryinfo("C:\Test")
dim myFile as fileinfo
for each extension in ext 'Gets Files For Each Extension Passed
for each myFile in dir.getfiles(extension) ' Adds Files To
ArrayList
files.add(myfile.fullname)
next
next
End Function
I didn't test this, and I hope this will still help you! :) Have a
great day! (Tip: If you have a problem hardcoding the size before you find
out how big it needs to be, then use an ArrayList. ArrayLists allow unlimited
calls to .Add without you having to specify the size of the list!)
Joseph MCAD
"Amjad" wrote:
Hi,
I want to write a For loop that will put file names of extensions (*.txt and
*.csv) in an array.
I had it work fine for one extension, and I need help making it work for two
extensions. My code is below:
Dim dir As New DirectoryInfo("C:\Test")
Dim fileNames(dir.GetFiles("*.txt").Length - 1)) As String
Dim myfile As FileInfo
For Each myfile In dir.GetFiles("*.txt")
fileNames(i) = myfile.FullName
i += 1
Next