(New to .NET) How do I load a directory of files into arraylist or collection?

A

AppleBag

Hello everybody,

I am beginning the .NET learning curve, and I have learned how to load
a listbox with a directory list of files using this code:

If FolderBrowserDialog1.ShowDialog() =
Windows.Forms.DialogResult.OK Then

ListBox1.DataSource =
System.IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath)

End If

But I do not actually need the listbox to be visible to the user for
what I am trying to do, and I would like to bypass it entirely by
looping through an arraylist or collection instead of looping through a
listbox. (I am going to do a routine that alters each file in the list
later).

So, my question for the pro's is, how would I have the list of files
load up in an arraylist or collection instead of the listbox?

Thank you very much in advance!
 
J

Jon Skeet [C# MVP]

AppleBag said:
Hello everybody,

I am beginning the .NET learning curve, and I have learned how to load
a listbox with a directory list of files using this code:

If FolderBrowserDialog1.ShowDialog() =
Windows.Forms.DialogResult.OK Then

ListBox1.DataSource =
System.IO.Directory.GetFiles(FolderBrowserDialog1.SelectedPath)

End If

But I do not actually need the listbox to be visible to the user for
what I am trying to do, and I would like to bypass it entirely by
looping through an arraylist or collection instead of looping through a
listbox. (I am going to do a routine that alters each file in the list
later).

Directory.GetFiles already returns an array - just don't put it into a
ListBox.
 
C

Cor Ligthert [MVP]

AppleBag,

If you want to avoid looping, than don't use a dotNet program language.

It cost no time for the computer and almost everything is based on that.

(Most end user tools do that for you behind the scene, although there are as
well a lot of methods in dotNet which do that for you).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top