PDA

View Full Version : Cercare un file in c


logan125842
26-01-2004, 09:39
Qualcuno di voi sa spiegarmi come faccio a cercare un file in tutto l'hd...per controllare le sottodirectory devo fare un algoritmo ricorsivo..se avete qualcosa che mi può aiutare rispondetemi...grazie

uso il borland c come compilatore

cionci
26-01-2004, 10:28
/* FFIND.C: This program uses the find functions to print
* a list of all files (and their attributes) with a .C extension
* in the current directory.
*/

#include <stdio.h>
#include <io.h>
#include <time.h>

void main( void )
{
struct finddata_t c_file;
long hFile;

/* Find first .c file in current directory */
if( (hFile = findfirst( "*.c", &c_file )) == -1L )
printf( "No *.c files in current directory!\n" );
else
{
printf( "Listing of .c 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 );

/* Find the rest of the .c files */
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 );
}
}
[/code]
Basta che cercare *.* e se trovi l'attributo A_SUBDIR allora è una sottodirectory è puoi chiamare la funzione ricorsivamente nelal sottodirectory... Se le costanti non vanno bene guarda nell'help del Borland ;)

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.