Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Choose text file-oldest by date/time

Posted on 2000-04-20
4
Medium Priority
?
272 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

722 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