Information générale
Catégorie:
Codage, syntaxe et commandes
I don't think there is a API/library routine that enables you to say "retreive oldest file or files by date". What you could do is use the _findfirst and _findnext routines to work through the directorys and files comparing the time_create, time_access, time_write members of the _finddata_t (whatever is appropriate to solve your problem).
I compiled the following code under Visual C++ 6.0 SP4, create a new WIN32 console application and turn off precompiled headers.
MSDN includes a LOT of information on this subject if you need to look up the structures, another good tip is to turn on the Browse Information under:-
Project->Project Settings->Browse Info->Build browse info file
This will allow you to right click on the structures and functions and jump to their definitions in the header/source files.
#include
#include
#include
void main( void )
{
struct _finddata_t find_file;
long hFile;
if( (hFile = _findfirst( "*.*", &find_file )) == -1L )
printf( "No files in current directory!\n" );
else
{
printf( "Listing of all files\n\n" );
printf( "\nRDO HID SYS ARC FILE DATE %25c SIZE\n", ' ' );
printf( "--- --- --- --- ---- ---- %25c ----\n", ' ' );
printf( ( c_file.attrib & _A_RDONLY ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_SYSTEM ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_HIDDEN ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_ARCH ) ? " Y " : " N " );
printf( " %-12s %.24s %9ld\n",
c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
while( _findnext( hFile, &c_file ) == 0 )
{
printf( ( c_file.attrib & _A_RDONLY ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_SYSTEM ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_HIDDEN ) ? " Y " : " N " );
printf( ( c_file.attrib & _A_ARCH ) ? " Y " : " N " );
printf( " %-12s %.24s %9ld\n",
c_file.name, ctime( &( c_file.time_write ) ), c_file.size );
}
_findclose( hFile );
}
}
HTH
Neil
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement