470,596 Members | 1,386 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

Sorting the file Name

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
Jul 22 '05 #1
1 2179
Abhijit Bhadra wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by James P | last post: by
20 posts views Thread by Xah Lee | last post: by
25 posts views Thread by Dan Stromberg | last post: by
5 posts views Thread by Cindy Lee | last post: by
5 posts views Thread by ^cypis^ vel. SQ9JTI | last post: by
7 posts views Thread by Kamal | last post: by
5 posts views Thread by jrod11 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.