Solved

hope this easy

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ question 3 74
c++, dynamic object by json 1 59
Precision Problem in C++ 7 48
DCT of  2D array using fftw in c++ 9 87
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

679 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