Solved

Choose text file-oldest by date/time

Posted on 2000-04-20
4
270 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
[X]
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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

710 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