Sorting the file Name

A

Abhijit Bhadra

Hi ,
In C++ , I have some files as per their date of creation .
The files are in the form of
maple01012005.log

maple01142005.log

maple01202005.log

sample01182005.log

sample01192005.log

sample01202004.log

sample01202005.log

ample012020051517.log

sample012020051522.log

So the general format of files are <file_name>ddmmyyyyhhmm .
Where hhmm are optional .
Now those file names I put into a list and calling sort() command .
sort obviously will not sort in the form of date .

Can anyone help me to implement sort function .

Thanks,
AB
 
K

Karl Heinz Buchegger

Abhijit said:
Hi ,
In C++ , I have some files as per their date of creation .
The files are in the form of
maple01012005.log

maple01142005.log

maple01202005.log

sample01182005.log

sample01192005.log

sample01202004.log

sample01202005.log

ample012020051517.log

sample012020051522.log

So the general format of files are <file_name>ddmmyyyyhhmm .
Where hhmm are optional .
Now those file names I put into a list and calling sort() command .
sort obviously will not sort in the form of date .

Can anyone help me to implement sort function .

You made yourself a lot of troubles by choosing a hard to parse
format for including the time stamp into the file name. If
possible change that first

eg.
sample012020052004.log
is that file sample.log created at the day = 01
month = 20
year = 2005
hour = 20
minute = 04
or is that file
sample0120.log created at the day = 20
month = 05
year = 2004

In any case. Every sort algorithm needs to compare 2 entries,
to decide which one is less.
In your case this means: locate the date/time stamp, extract
that and base your comparison on that instead of the full
filename.

So your first goal is: to locate and extract the time/date stamp.
Once you have that and you still have problems inserting that
information into a sorting algorithm, come back and ask for
help again. But for this, you definitly need the date/time stamp
alone.
 

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

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top