home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 8 / dirdump.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.7 KB  |  79 lines

  1. /* DIRDUMP.C */
  2.  
  3. #define AllAttributes   0x3F            /* bits set for all attributes */
  4.  
  5. main()
  6. {
  7.         static  char CurrentDir[64];
  8.         int     ErrorCode;
  9.         int     FileCount = 0;
  10.  
  11.         struct
  12.         {
  13.           char    reserved[21];
  14.           char    attrib;
  15.           int     time;
  16.           int     date;
  17.           long    size;
  18.           char    name[13];
  19.         }         DTA;
  20.  
  21. /* display current directory name */
  22.  
  23.         ErrorCode = GetCurrentDir( CurrentDir );
  24.         if( ErrorCode )
  25.         {
  26.           printf( "\nError %d:  GetCurrentDir", ErrorCode );
  27.           exit( 1 );
  28.         }
  29.  
  30.         printf( "\nCurrent directory is \\%s", CurrentDir );
  31.  
  32.  
  33. /* display files and attributes */
  34.  
  35.         SetDTA( &DTA );                 /* pass DTA to MS-DOS */
  36.  
  37.         ErrorCode = FindFirstFile( "*.*", AllAttributes );
  38.  
  39.         while( !ErrorCode )
  40.         {
  41.           printf( "\n%12s -- ", DTA.name );
  42.           ShowAttributes( DTA.attrib );
  43.           ++FileCount;
  44.  
  45.           ErrorCode = FindNextFile( );
  46.         }
  47.  
  48. /* display file count and exit */
  49.  
  50.         printf( "\nCurrent directory contains %d files\n", FileCount );
  51.         return( 0 );
  52. }
  53.  
  54.  
  55. ShowAttributes( a )
  56. int     a;
  57. {
  58.         int     i;
  59.         int     mask = 1;
  60.  
  61.         static char *AttribName[] =
  62.         {
  63.           "read-only ",
  64.           "hidden ",
  65.           "system ",
  66.           "volume ",
  67.           "subdirectory ",
  68.           "archive "
  69.         };
  70.  
  71.  
  72.         for( i=0; i<6; i++ )            /* test each attribute bit */
  73.         {
  74.           if( a & mask )
  75.             printf( AttribName[i] );    /* display a message if bit is set */
  76.           mask = mask << 1;
  77.         }
  78. }
  79.