Sample Exercises

Filesystem: Report

Return to exercise list

Write a program that displays information about the files and/or directories listed on the command line. For each word on the command line, check if it is a file or directory, and do the following:

If it is a file, display the file size and how long ago it was most recently modified, like this:

foo.txt contains 12345 bytes and was last modified 1.5 days ago.

If it is a directory, then use opendir and readdir to read it, and display the names of each file or directory therein and whether it is a file or directory. (Do not recursively display this information about the contents of sub-directories...) Example:

. is a directory
.. is a directory
foo.txt is a file
fsreport.plx is a file

Solution for Report

Solution