#include #include #include "dirent.h" #include #pragma warning (disable:4996) #ifndef MAX_PATH #define MAX_PATH 1023 #endif #define SEPARATOR "\\" char *commandName; #define isDirectory( b ) ( ( b.st_mode & S_IFMT ) == S_IFDIR ) void processDir( const char *dirName ) { DIR *dp = opendir( dirName ); struct dirent *slot = NULL; printf( "\n\n%s\n", dirName ); /* Read each entry */ for( slot = readdir( dp ); slot != NULL; slot = readdir( dp ) ) { struct stat buf; char *theTime; int isDir; char completeFileName[ MAX_PATH ]; sprintf( completeFileName, "%s%s%s", dirName, SEPARATOR, slot->d_name ); if( stat( completeFileName, &buf ) == -1 ) { printf( "%s: Error stating file %s\n", commandName, slot->d_name ); continue; } isDir = isDirectory( buf ); theTime = ctime( &buf.st_mtime ); theTime[ 24 ] = '\0'; printf( "%s " , theTime ); if( isDir ) printf( " " ); else printf( " " ); printf( "%8d ", buf.st_size ); printf( "%s ", slot->d_name ); printf( "\n" ); if( isDir && strcmp( slot->d_name, "." ) && strcmp( slot->d_name,".." ) ) processDir( completeFileName ); } closedir( dp ); } int main( int argc, char * argv[ ] ) { int i; commandName = argv[ 0 ]; if( argc == 1 ) processDir( "." ); else { for( i = 1; i < argc; i++ ) { printf( "Processing... %s:\n", argv[ i ] ); processDir( argv[ i ] ); } } return 0; }