Back to Code Snippets / Powrót do Strzępów Kodu


#include <windows.h>
#include <stdio.h>

int
show_files( const char *path )
{
 HANDLE          search;
 WIN32_FIND_DATA data;
 char            buf[1024];
 
 /* seek for dirs first */
 sprintf( buf, "%s\\*", path );
 
 search = FindFirstFile( buf, &data );
 if( search == INVALID_HANDLE_VALUE )
 {
   return 1;
 }
 
 do
 {
   /* skip special dir markers */
   if( ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
       ( ( !strcmp( data.cFileName, "." ) ) ||
         ( !strcmp( data.cFileName, ".." ) ) ) )
     continue;

         
   printf( "[%4s] %s\\%s\n",
       data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? "DIR" : "FILE",
       path, data.cFileName );
 }
 while( FindNextFile( search, &data ) );
 
 FindClose( search );

 return 0;
}

int
main( void )
{
 show_files(".");

   
 return 0;
}

Add a comment:

Nick:
URL (optional):
Math captcha: 10 ∗ 9 + 9 =