CMPS 105: Systems Programming

Programming Assignment #3: File Searching


Remember: your programming assignment must be turned in online.

The Basics

The goal of this assignment is to get familiar with directories (and perhaps with files).

In this assignment, you are to implement an efficient file searching program. It will be called like this:

search file path

where "file" is a filename which may include * (matches anything) or ? (matches any single character), and "path" is the pathname of the starting point of the search.

The program will traverse the entire directory structure starting at the designated path and report all files that match the filename provided.


The Details

To implement your program, you will need to use the systems calls that access directories: opendir(), readdir(), and closedir(). You will also need to use stat() to determine whether a given file is a directory (which you should therefore also search).

Your program should output whatever information you think useful, including the location of all files matching the filename provided, any useful information about those files (how big it is, when it was created, and anything else useful), and how long the search took.

My advice is to implement this program as follows:

1. Get it to files with the correct filename, without * and ?, in a single directory, only printing out the full pathname of anything that matches

2. Get stat working so you can tell if it is a file or directory, and so you can print out useful information about the file

2. Enhance it to search subdirectories (perhaps recursively)

3. Add in support for * and ?

For extra credit (10 points), you may also include a third parameter that specifies a string to search for in any file that matches the filename, and only report those files that have the right name and contain the string. Called like this, "search file path" it would emulate find (more or less), while called like this "search * path string" it would emulate grep. Called other ways, it would provide the combined functionality of both.

Note: You must check and correctly handle all return values. This means that you need to read the man pages for each function to figure out what the possible return values are, what errors they indicate, and what you must do when you get that error.


What to turn in

Your code, a working makefile, and your design document. In addition, include a README file to explain anything unusual to the TA — testing procedures, etc.

REMEMBER: Do not submit object files, assembler files, or executables. Every file in the submit directory that could be generated automatically by the compiler or assembler will result in a deduction from your programming assignment grade.


sbrandt@cse.ucsc.edu