Dates

  • Thread starter Thread starter Trond Hoiberg
  • Start date Start date
T

Trond Hoiberg

I have a lot of files in a folder. The files are created on different dates.
Some of the files have been created on the same date. I need to build an
array with unique dates. So if 5 files have the same "created date" I only
need one date in the array.

5 files created on 22.05.2004
3 files created on 28.05.2004
will result in an array with 2 dates
(in the array 22052005 and 28052004)

Have been struggling with this for a week now so any code that could help
would be like x-mas :-)
Best regards
Trond
 
Trond Hoiberg said:
I have a lot of files in a folder. The files are created on different dates.
Some of the files have been created on the same date. I need to build an
array with unique dates. So if 5 files have the same "created date" I only
need one date in the array.

Here're a couple of hints:

o Use ArrayList.
o Check if the ArrayList already Contains[*] the value before adding it.

If you're still stuck, post your attempts here, and someone can then point
out any mistakes you've made.

[*] That was a hint within a hint. :-)
 
Trond,

I would just use a hashtable. Basically, cycle through all of the
files, and add the value to the hashtable. The key is the date of the file,
while the value can be anything (I usually use booleans).

Then, you can get the Keys property on the hashtable, and it will have a
unique list of the dates that are the keys in the hashtable.

Hope this helps.
 
I actually wouldn't use an ArrayList, as the Contains method would cycle
through each element in the array (and the more unique elements there are,
the longer it will take). A Hashtable would be much, much quicker
(overall).

The concept is the same though.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

C# Learner said:
Trond Hoiberg said:
I have a lot of files in a folder. The files are created on different
dates.
Some of the files have been created on the same date. I need to build an
array with unique dates. So if 5 files have the same "created date" I
only
need one date in the array.

Here're a couple of hints:

o Use ArrayList.
o Check if the ArrayList already Contains[*] the value before adding it.

If you're still stuck, post your attempts here, and someone can then point
out any mistakes you've made.

[*] That was a hint within a hint. :-)
 
OK, thanks. As i said i'm a newbee so i guess i still have to try to fig it
out myself :-)
I have tried with various collections but i dont get it right. Thats why i
hoped someone had some code that could help me out.
Best regards
Trond

Nicholas Paldino said:
Trond,

I would just use a hashtable. Basically, cycle through all of the
files, and add the value to the hashtable. The key is the date of the
file, while the value can be anything (I usually use booleans).

Then, you can get the Keys property on the hashtable, and it will have
a unique list of the dates that are the keys in the hashtable.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Trond Hoiberg said:
I have a lot of files in a folder. The files are created on different
dates. Some of the files have been created on the same date. I need to
build an array with unique dates. So if 5 files have the same "created
date" I only need one date in the array.

5 files created on 22.05.2004
3 files created on 28.05.2004
will result in an array with 2 dates
(in the array 22052005 and 28052004)

Have been struggling with this for a week now so any code that could help
would be like x-mas :-)
Best regards
Trond
 
Back
Top