Work 12: Please follow the dir(rections)

posted Nov 1, 2018, 7:04 AM by JonAlf Dyrland-Weaver   [ updated Nov 2, 2018, 5:45 AM ]
New and improved instructions:
  • Your program should handle user input as follows:
    • If a command line argument is entered, use that as the directory to scan.
    • If not, the program should ask the user to enter a directory to scan.
    • In either case, don't assume your user knows what they are doing, if an invalid directory is entered, take reasonable action (*ahem* errno *cough cough*)

With your *new* table buddy, write a program that will gather various information about a directory, specifically:
  • list all the files in the directory
  • specify which files are directories (if any)
  • show the total size of all the regular files the directory
    • note that you do not have to recursively go through any subdirectories to find their size for this part (unless you want to, but that is not a simple task)
  • Have the program scan the current directory
  • Possible enhancements:
    • Recursively list the files in any subdirectories, update the total to include the total size of subdirectories
    • Print out the size in a more readable format (like using KB, MB, GB for -byte prefixes)

Github link:
https://github.com/mks65/dirinfo.git

Below is sample output, yours may differ, but as long as it presents the information requested above you will receive full credit.
$ ./a.out
Statistics for directory: .
Total Diectory Size: 13453 Bytes
Directories:
        .
        ..
Regular files:
        a.out
        dirinfo.c
        dirinfo.c~
        dirstuff.c
        dirstuff.c~

$ ./a.out
Statistics for directory: .
Total Diectory Size: 17766 Bytes
Directories:
        .
        ..
        dir
        structRW
Regular files:
        a.out
        error.log
        filelist
        files.c
        read.c
        ReadTest
        redirect.c
        redirect.c~
        redirect_full.c
        redirect_full.c~
        redirTest
        statfiles.c
        statfiles.c~
        write.c
        WriteTest


Comments