Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

hope this easy

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
jafrazee
Asked:
jafrazee
1 Solution
 
Karl Heinz KremerCommented:
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
 
tinchosCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now