Solved

Choose text file-oldest by date/time

Posted on 2000-04-20
4
269 Views
Last Modified: 2010-04-10
I need to choose a DOS text file by oldest date/time-Please Help
0
Comment
Question by:rgcomm
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
MT_MU earned 50 total points
ID: 2736050
something like this should work.

(Assuming VC and win 95/98/nt)

#include <stdio.h>
#include <io.h>
#include <time.h>
#include <string.h>

void main( void )
{
      struct _finddata_t c_file;
      long hFile;
      time_t oldest_time = (time_t)-1;
      char save_file_name[20];

      if( (hFile = _findfirst( "*.*", &c_file )) == -1L )
            printf( "Not files found." );
      else
      {
            if (!(c_file.attrib & _A_SUBDIR))
            {      // should never happen
                  oldest_time = c_file.time_write;
                  strcpy(save_file_name,c_file.name);
            }
            while( _findnext( hFile, &c_file ) == 0 )
            {
                  if (!(c_file.attrib & _A_SUBDIR))      // ignore subdirs...
                  {
                        if (oldest_time == (time_t)-1)
                        {
                              oldest_time = c_file.time_write;
                              strcpy(save_file_name,c_file.name);
                        }
                        if (oldest_time > c_file.time_write)
                        {
                              oldest_time = c_file.time_write;
                              strcpy(save_file_name,c_file.name);
                        }
                  }
            }
            _findclose( hFile );
      }
      if (oldest_time != -1)
      {
            printf("Oldest file %s", save_file_name);
      }
}

0
 

Author Comment

by:rgcomm
ID: 2736106
No MFC or VC, just standard c++,Please.
0
 

Author Comment

by:rgcomm
ID: 2736873
Adjusted points from 25 to 50
0
 

Author Comment

by:rgcomm
ID: 2736874
I would like some code that I can port to other platforms, but this is a start.

Thank You Very Much.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

828 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