Computer Sciences Department logo

CS 368-1 (2010 Summer) — Day 8 Homework

Due Monday, July 26th, at the start of class.


Display information about files in directories, recursively. Along the way, you will use many built-in functions and modules.


The script will take one directory path as input — you can ask the user for the directory or simply hard-code it into your script. The script will process all files within the directory, recursively. Sort the directories that are found (standard string sort is fine), and print a report for each directory in order: list all of the files in the directory, sorted from largest file to smallest, and print the file size, the (formatted) last modification time, and the name of the file (without the directory prefix) — see the example output below for a better picture of what to do.

You may assume that there are only files and directories. Do not print information for the directories '.' and '..'.

Example Output

Directory </p/course/cs368-cat/public/html/2010>
        9641   2010-07-01 16:25:22   resources.html
        7068   2010-07-20 13:59:20   index.html
        1541   2009-07-08 09:52:37   cs-logo.gif
         707   2010-07-20 16:16:16
         658   2009-07-10 15:49:32   368-1.css

Directory </p/course/cs368-cat/public/html/2010/01-introduction>
      115281   2010-07-12 10:18:22   cs368-1-2010-summer-01-0712M.pdf
        2369   2010-07-12 09:51:49   homework-01-assignment.html

Directory </p/course/cs368-cat/public/html/2010/02-syntax>
      131814   2010-07-13 09:56:27   cs368-1-2010-summer-02-0713T.pdf
        2974   2010-07-13 10:02:07   homework-02-assignment.html
         642   2010-07-13 16:40:02   in-class-code.html

Directory </p/course/cs368-cat/public/html/2010/03-collections>
      114186   2010-07-15 09:44:21   cs368-1-2010-summer-03-0715R.pdf
        4144   2010-07-15 09:53:12   homework-03-assignment.html

Directory </p/course/cs368-cat/public/html/2010/04-basic-io>
     1454670   2009-07-13 13:46:40   homework-04.txt
      132377   2010-07-16 10:12:51   cs368-1-2010-summer-04-0716F.pdf
        3389   2010-07-16 10:34:29   homework-04-assignment.html

Directory </p/course/cs368-cat/public/html/2010/05-subroutines>
      113456   2010-07-19 10:08:07   cs368-1-2010-summer-05-0719M.pdf
        3213   2010-07-19 10:30:29   homework-05-assignment.html
        1133   2010-07-19 14:39:02   in-class-code.html

Directory </p/course/cs368-cat/public/html/2010/06-data-structures>
      237215   2009-07-20 23:57:39   example_access_log
      124530   2010-07-20 09:49:22   cs368-1-2010-summer-06-0720T.pdf
        8092   2010-07-20 10:14:27   homework-06-assignment.html

Directory </p/course/cs368-cat/public/html/2010/08-standard-library>
        2484   2010-07-20 16:15:22   homework-08-assignment.html


The following hints are a bit … vague. I am doing this to encourage you to look up some functions and modules online. You need to learn to do this anyway, so consider it good practice.


Do the work yourself, consulting reasonable reference materials as needed; any reference material that gives you a complete or nearly complete solution to this problem or a similar one is not OK to use. Asking the instructors for help is OK, asking other students for help is not.

Hand In

A printout of your output on a single sheet of paper. Be sure to put your own name in the initial comment block of the code. Identifying your work is important, or you may not receive appropriate credit.