Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Oldest File Revisited...
Message
De
21/07/2000 03:31:41
 
 
À
Tous
Information générale
Forum:
Visual C++
Catégorie:
Codage, syntaxe et commandes
Titre:
Oldest File Revisited...
Divers
Thread ID:
00395245
Message ID:
00395245
Vues:
34
Hello,
Thanks Neil for your help before Igot it sorted but now I am having problems with part two.


This code is going into a DLL but I put it in a console app for easier debugging. What I am trying to do is return the oldest file in a folder. I need this to call from an Oracle Procedure (to pick up text files and process them).

I can't seem to figure out how to find the oldest file in the directory maybe someone can help.

I am having problems with this section of code:

while( _findnext( hFile, &c_file ) == 0 )
{
newtime = c_file.time_write;
if(ctime(&oldtime) > ctime(&newtime)){
oldtime = newtime;
result= c_file.name;
n=n+1;
}
}

It correctly moves through the current directory I can see via the print lines. But the comparison if(ctime(&oldtime) > ctime(&newtime)) or if(oldtime > newtime) never evaluates to true when by my accounts it should.

Any ideas.

**********************************************************************************************
The entire program is included here.
BTW I noticed that the includes don't show up in messages in this formum so I included:
stdio.h,io.h,time.h,Windows.h,direct.h,comdef.h,iostream.h


****************************************************************************************************
#include
#include
#include
#include
#include

#include
#include


int main(int argc, char* argv[])
{
//example Oldest('c:\temp','*.txt')
static struct _finddata_t c_file;
long hFile;
char *result;
int n;
n=1;

if( (hFile = _findfirst("*.*", &c_file )) == -1L )
{
result="No files!";

}
else
{
result = c_file.name;

//Store oldest time...
time_t oldtime;
time_t newtime;
oldtime=c_file.time_write;
//need to get oldest file....

while( _findnext( hFile, &c_file ) == 0 )
{
newtime = c_file.time_write;
printf( " %.24s \n",
ctime( &( newtime ) ));
printf("\t %d\n",ASSERT(ctime(&oldtime) > ctime(&newtime)));

if(ctime(&oldtime) > ctime(&newtime)){
oldtime = newtime;
result= c_file.name;
printf( " %.24s \n",
ctime( &( oldtime ) ));

printf( " %-12s\n",result);
n=n+1;
}

}
//end new code for oldest file
//

//qsort( c_file, (size_t)n+1, sizeof( char * ),compare );

}
_findclose(hFile);

printf( " %-12s\n",result);
printf( "\t %d\n\n", n );


return 0;
}
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform