/** * THIS CODE DOESN'T WORK YET. FIXES TO COME IN THURSDAY'S LECTURE! */ #include #include #include #include #include #include #include #include #include #include "dirent.h" void listFiles( const char *directory ) { DIR *dp; struct dirent *slot; struct stat buffer; if( ( dp = opendir( directory ) ) == NULL ) { fprintf( stderr, "Error opening %s\n", directory ); return; } for( slot = readdir( dp ); slot != NULL; slot = readdir( dp ) ) { if( stat( slot->d_name, &buffer ) != 0 ) { fprintf( stderr, "Can't stat %s\n", slot->d_name ); continue; } if( ( buffer.st_mode & _S_IFMT ) == _S_IFDIR ) printf( "(DIR)" ); else printf( " " ); printf( "%40s", slot->d_name ); printf( " %8ld", buffer.st_size ); printf( " %s", ctime( &buffer.st_mtime ) ); } closedir( dp ); } int main( ) { listFiles( "." ); return 0; }