By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,327 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,327 IT Pros & Developers. It's quick & easy.

make an array of filenames

P: n/a
Hello, I want to make an array of filenames in a directory.
I started with the following code:

Dim DirInfo As IO.DirectoryInfo = New IO.DirectoryInfo("N:\queues\jurgen\")
Dim FileInfo As IO.FileInfo() = DirInfo.GetFiles()

Now I want to put the members "Name" and "LastWriteTime" in an array.
After that I want to sort the array on "Name"

Can anyone tell me how to do this?

Any help/hints much appreciated.

Best regards, Jurgen
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
HI Jurgen,

Because that a Array holds only one item, you can choose to make your own
class which holds two items and add that to the array or make completly your
own class. I show you first the arraylist.

A little bit quick in psuedo written

\\\\
dim myarray() as new arraylist
dim myItems as new clsMyItems
than a loop where you add doing from your collected fileitems
for each bla bla
myItems.Name = myfileitem.Name
myItems..... etc
myArray.add(myItems)
next
///
\\\
Private Class clsMyItems
dim [Name] as string
dim LastWriteTime as string
end class
///
When you need it you can write with option strict on.

dim myname as string = directcast(myarray,clsMyItems).Name

You can as well do it completly in your own class OHM shows an example of
that in the thread from Agnes, Combobox return more than 1 items about 10 or
20 threads below

I hope this helps?

Cor
Nov 20 '05 #2

P: n/a
Hi,

Array elements can store only a 'single information'. So, you wont be able
to store both Name and LastWriteTime in an array element.
May be, you can make use of System.Data.DataTable to accomplish the same.

"Jurgen Oerlemans" <ju**************@envirolab.no_spam.nl> wrote in message
news:41*********************@news.wanadoo.nl...
Hello, I want to make an array of filenames in a directory.
I started with the following code:

Dim DirInfo As IO.DirectoryInfo = New IO.DirectoryInfo("N:\queues\jurgen\")
Dim FileInfo As IO.FileInfo() = DirInfo.GetFiles()

Now I want to put the members "Name" and "LastWriteTime" in an array.
After that I want to sort the array on "Name"

Can anyone tell me how to do this?

Any help/hints much appreciated.

Best regards, Jurgen

Nov 20 '05 #3

P: n/a
Thanx Cor,

You have put me on the right track!

Jurgen

"Cor Ligthert" <no**********@planet.nl> schreef in bericht
news:%2***************@TK2MSFTNGP10.phx.gbl...
HI Jurgen,

Because that a Array holds only one item, you can choose to make your own
class which holds two items and add that to the array or make completly your own class. I show you first the arraylist.

A little bit quick in psuedo written

\\\\
dim myarray() as new arraylist
dim myItems as new clsMyItems
than a loop where you add doing from your collected fileitems
for each bla bla
myItems.Name = myfileitem.Name
myItems..... etc
myArray.add(myItems)
next
///
\\\
Private Class clsMyItems
dim [Name] as string
dim LastWriteTime as string
end class
///
When you need it you can write with option strict on.

dim myname as string = directcast(myarray,clsMyItems).Name

You can as well do it completly in your own class OHM shows an example of
that in the thread from Agnes, Combobox return more than 1 items about 10 or 20 threads below

I hope this helps?

Cor

Nov 20 '05 #4

P: n/a
* "Jurgen Oerlemans" <ju**************@envirolab.no_spam.nl> scripsit:
Hello, I want to make an array of filenames in a directory.
I started with the following code:

Dim DirInfo As IO.DirectoryInfo = New IO.DirectoryInfo("N:\queues\jurgen\")
Dim FileInfo As IO.FileInfo() = DirInfo.GetFiles()

Now I want to put the members "Name" and "LastWriteTime" in an array.
After that I want to sort the array on "Name"


I would keep the data in 'FileInfo' objects, write a custom comparer
that compares the objects by name ('IComparer') and sort them using
'Array.Sort(<array>, <comparer>)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #5

P: n/a
> > Now I want to put the members "Name" and "LastWriteTime" in an array.
After that I want to sort the array on "Name"


I would keep the data in 'FileInfo' objects, write a custom comparer
that compares the objects by name ('IComparer') and sort them using
'Array.Sort(<array>, <comparer>)'.


Why?

Seriously

Cor
Nov 20 '05 #6

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Now I want to put the members "Name" and "LastWriteTime" in an array.
After that I want to sort the array on "Name"


I would keep the data in 'FileInfo' objects, write a custom comparer
that compares the objects by name ('IComparer') and sort them using
'Array.Sort(<array>, <comparer>)'.


Why?


I think using a custom comparer is an easy-to-extend approach, but there
are many other ways to answer the question too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.