Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hope this easy

Posted on 2003-12-11
2
Medium Priority
?
318 Views
Last Modified: 2012-08-13
i am importing images from a directory and sub dirs into our software for processing.
my code is as follows
it all works great with no problems.
but i would like to be able to sort the directory by file date.
is there a call to do this?   or
will i have to create arrays and sort the array?

thank you.


int hDir = _findfirsti64(getimgdir,&dirinfo);
  wsprintf(getname, "%s\\*.tif",Td.ImgDir);
  int dirloop = 0;
  if(hDir>-1){
    do{
      int hFile = _findfirsti64(getname,&fileinfo );
      int ret = 0;
      if(hFile>-1){
        do{
          if(strlen(dirinfo.name)<3 && dirloop==0){////////////////check root for tiffs
            wsprintf(getimage.getimg,"%s\\%s",Td.ImgDir,fileinfo.name);
          }else{
            wsprintf(getimage.getimg,"%s\\%s\\%s",Td.ImgDir,dirinfo.name,fileinfo.name);
          }
         /////////////////////////////do calls for processing images                  
         ret = _findnexti64(hFile, &fileinfo );
        }while(ret ==0);
      }
/////////////////////////////find next folder and loop again.
            
0
Comment
Question by:jafrazee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 200 total points
ID: 9920360
I would read the file names into a map<time_t, string>, with the key being the time the file was last modified. You can get this time by calling _stat on the file:


#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <map>

using namespace std;

int result;
struct _stat buf;
map<time_t, string> timeMap;
...

   result = _stat( "your_file_name", &buf );

   if (result != 0 )
   {
      ... handle the error ...
   }
   else
   {
      // add to the map:
      timeMap[&buf.st_atime] = your_file_name;
   }
}

Once all the data is collected, you just iterate over the map and have the file names in the order they were modified. If you need the reverse order, just use a reverse_iterator.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10356304
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: khkremer {http:#9920360}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question