home *** CD-ROM | disk | FTP | other *** search
- /* DIRDUMP.C */
-
- #define AllAttributes 0x3F /* bits set for all attributes */
-
- main()
- {
- static char CurrentDir[64];
- int ErrorCode;
- int FileCount = 0;
-
- struct
- {
- char reserved[21];
- char attrib;
- int time;
- int date;
- long size;
- char name[13];
- } DTA;
-
- /* display current directory name */
-
- ErrorCode = GetCurrentDir( CurrentDir );
- if( ErrorCode )
- {
- printf( "\nError %d: GetCurrentDir", ErrorCode );
- exit( 1 );
- }
-
- printf( "\nCurrent directory is \\%s", CurrentDir );
-
-
- /* display files and attributes */
-
- SetDTA( &DTA ); /* pass DTA to MS-DOS */
-
- ErrorCode = FindFirstFile( "*.*", AllAttributes );
-
- while( !ErrorCode )
- {
- printf( "\n%12s -- ", DTA.name );
- ShowAttributes( DTA.attrib );
- ++FileCount;
-
- ErrorCode = FindNextFile( );
- }
-
- /* display file count and exit */
-
- printf( "\nCurrent directory contains %d files\n", FileCount );
- return( 0 );
- }
-
-
- ShowAttributes( a )
- int a;
- {
- int i;
- int mask = 1;
-
- static char *AttribName[] =
- {
- "read-only ",
- "hidden ",
- "system ",
- "volume ",
- "subdirectory ",
- "archive "
- };
-
-
- for( i=0; i<6; i++ ) /* test each attribute bit */
- {
- if( a & mask )
- printf( AttribName[i] ); /* display a message if bit is set */
- mask = mask << 1;
- }
- }
-