#pragma warning (disable:4996) #include #include #include #include #include #include "dirent.h" #define SEPARATOR_CHAR '/' #ifndef MAX_PATH #define MAX_PATH 1023 #endif void processDir( const char *name ); int main( int argc, char * argv [ ] ) { if( argc == 1 ) processDir( "." ); else while( --argc ) processDir( *++argv ); return 0; } void processDir( const char *dirName ) { DIR *dp; struct dirent *slot; struct stat buf; if( ( dp = opendir( dirName ) ) == NULL ) { fprintf( stderr, "Error opening %s\n", dirName ); return; } for( slot = readdir( dp ); slot != NULL; slot = readdir( dp ) ) { char *timeRepresentation; int isDir; char fullName[ MAX_PATH + 1 ]; sprintf( fullName, "%s%c%s", dirName, SEPARATOR_CHAR, slot->d_name ); if( stat( fullName, &buf ) == -1 ) { fprintf( stderr, "Error stating %s\n", fullName ); continue; } timeRepresentation = ctime( &buf.st_mtime ); timeRepresentation[ 24 ] = '\0'; isDir = ( buf.st_mode & S_IFMT ) == S_IFDIR; printf( "%s ", timeRepresentation ); printf( "%8d ", buf.st_size ); if( isDir ) printf( " (DIR) " ); else printf( " " ); printf( "%11o ", buf.st_mode ); printf( "%s", fullName ); printf( "\n" ); if( isDir ) { if( strcmp( slot->d_name, "." ) != 0 && strcmp( slot->d_name, ".." ) != 0 ) processDir( fullName ); } } closedir( dp ); }