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 6 2687
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
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
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
* "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/>
> > 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
* "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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lowell Kirsh |
last post by:
I have a script which I use to find all duplicates of files within a
given directory and all its subdirectories. It seems like it's longer
than it needs to be but I can't figure out how to shorten...
|
by: Dan =o\) |
last post by:
Hey guys,
I'm getting really annoyed with this array... After selecting some items
from a list view, I take the selected text from the first column and store
it in an array, I then pass this...
|
by: Paul in Toronto |
last post by:
Got this assignment in my VB .NET class. The program's basically a picture
viewer that lets you add your pictures to an array so you can cycle through
them once the file's been opened. So you...
|
by: n33470 |
last post by:
We have a web site that is being converted from the 1.1 format into
2.0. I've noticed that after the web project has been converted, the
first time that the solution is opened in VS, all of the...
|
by: vladislavf |
last post by:
Hi All,
I need to pass array of strings from C++/CLI to unmanaged C++ function.
(The unmanaged API signatire is : int Combine(int NumOfInputFiles,
wchar_t **names) and I want to call it from...
|
by: Kyote |
last post by:
Sorry, but I have no idea how to phrase the subject better than that.
I've come across this a few different times and decided to ask in case
there's a way to do it. It would simplify things a bit...
|
by: Kyote |
last post by:
I'm trying to persist a list of filenames. I've made a custom
collection and a FileName class:
'Class to hold file name information
Public Class FileNames
Public fullName As String
Public...
|
by: Jeffrey Walton |
last post by:
Hi All,
I have an array of 16x16 bitmaps (60 total). I've tried adding the
array to the ImageList with the Add method, but the TreeView paints as
if no BMP is present.
The problem is the...
|
by: sritejv |
last post by:
Hi guys,
i m have trouble with reading strrings and storing them in a 2d array and printing them
(1)for(y=0;y<5;y++)
{
printf("enter filenames \n");
scanf("%s",&fnames);
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |