Solved

Choose text file-oldest by date/time

Posted on 2000-04-20
4
263 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

11 Experts available now in Live!

Get 1:1 Help Now