Solved

hope this easy

Posted on 2003-12-11
2
313 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
2 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

770 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