make an array of filenames

J

Jurgen Oerlemans

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
 
C

Cor Ligthert

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
 
S

Shiva

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.

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
 
H

Herfried K. Wagner [MVP]

* "Jurgen Oerlemans said:
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>)'.
 
C

Cor Ligthert

Now I want to put the members "Name" and "LastWriteTime" in an array.
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
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:

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

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