hope this easy

Posted on 2003-12-11
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;
      int hFile = _findfirsti64(getname,&fileinfo );
      int ret = 0;
          if(strlen(<3 && dirloop==0){////////////////check root for tiffs
         /////////////////////////////do calls for processing images                  
         ret = _findnexti64(hFile, &fileinfo );
        }while(ret ==0);
/////////////////////////////find next folder and loop again.
Question by:jafrazee
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
LVL 44

Accepted Solution

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 ...
      // 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.

Expert Comment

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.

EE Cleanup Volunteer

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embarcadero WebBroker REST server endpoint parameters 2 118
c++ reading data from file into two dimensional array 3 150
Gaming Software 1 39
Bitwise and to sum elements 2 54
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 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