Hi There,

Proberly a really simple request but im desperate for help none the same lol,

I need to write some code that, takes filenames from a folder, and displays them in an order in a list. (Im using Visual Studio btw) lol.

The file names are in the format of

bghtyhgfr5674456_120411_3215.

The last four digits the time, middle set the date. Currently my code can read these file names and saves them as strings however i need to display them in time/date order, most recent first.

What is the best way to go about this?

Thanks in advance
James

Recommended Answers

All 6 Replies

I should use the string split methodand split on the underscore and also sheck out the members of the DateTime struct.

the best option would be to use the string split method as ddanbe suggested,
when you do so, instead of an array size of 3 that you expect it to be, you would also get a empty string array at index 0, may be u can use the trim method or make sure you handle that in the loop.


bghtyhgfr5674456_120411_3215.

The last four digits the time, middle set the date.

How is 3215 the time?? What it represents? Seconds?
Because 32hours and 15 minutes cannot be in one day!

Yeah 3215 seems a bit off for time.

it could be 3 hrs, 21 mins and 5 seconds...

commented: Good thinking! +14

A simple Split is fine if all you have to do is split at the underscores and pass the parts off to date/time parsers, but it starts to get messy if you have to do more text manipulation after the split.

This might be slightly overkill for the posted problem, but I suggest you become familiar with regular expressions (if you aren't already) as something to keep in mind for when you have to parse formatted text that isn't dead simple.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.