Solved

hope this easy

Posted on 2003-12-11
2
311 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now