Solved

Choose text file-oldest by date/time

Posted on 2000-04-20
4
265 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

19 Experts available now in Live!

Get 1:1 Help Now