Question
###you are required to create a C program### which works with command line arguments. The arguments themselves may or may not be present on the
###you are required to create a C program### which works with command line arguments. The arguments themselves may or may not be present on the command line. Your code will have to adapt itself to accommodate for this. The aim of this lab is to familiarize yourself with reading and processing directories as well as extracting file attributes using the stat() system call. You are essentially writing your own version of the long format of the ls command. You will need to customize your output to match the following specifications: You program must accept the following parameters (if present): -o: specifies the minimum age of the files (modification timestamp) to be listed from the target directory. The -o argument will be followed by an integer (as a separate parameter to make things easier if you wish). This integer will represent the minimum number of days old the files can be in order for them to be included in your listing. As an example "-o 3" passed as arguments would mean: list all files that have been modified more than 3 days ago (from the current system time). -y: specifies the age of the newest files (modification timestamp) to be listed from the target directory. The -y argument will be followed by an integer (as a separate parameter to make things easier if you wish). This integer will represent the maximum number of days old the files need to be in order for them to show up in your listing. You can think of the -y to represent YOUNGER THAN. As an example "-y 7" passed as arguments should represent list all files whose modification timestamp is less than 7 days older than the current system time. -l (lower case L): This specifies a minimum file size for the files to be listed. In essence, list all files that are LARGER than the value given. -s: List all files which are smaller than the value given. So this is the maximum size a file can be to show up in the listing. You should use the time() functions to find the current epoch time. You can then add/subtract the appropriate number of second (ignoring leap years) to get a valid timestamp to compare to the stat() values. directory_path: the last argument on the command line should be a directory specification. Use this parameter to point your code to a specific directory whose content you want to list. If this parameter is NOT there, the current working directory should be assumed ( i.e. ./). You will be required to run your program against the /home/COIS/3380/lab3 directory on the loki.trentu.ca server. Your code however should work with any directory path. You can assume that any path over 4096 characters can be rejected by your code as too long. You should select a number of different values for the parameters. Larger than X but small than Y. Smaller than Z but created in the last 10 days. Things like that. It is important to use modular programming techniques (i.e. functions) as the code from this lab may be used in upcoming labs. It is strongly recommended that you work on a function to generate the appropriate formatting of the information returned from the stat() function for a single file before implementing it for the whole directory. If you are not using the getopt() function, you need not implement logic to ensure that the -o/-y options are followed by integers (when present). Your code can "assume" the argv[] elements directly following the -o, y, l and -s are integers, just to make things simpler. When you run your code, just make sure to put the proper values on the command line. The target directory for your code must be the last parameter passed on the command line (if present. If not your code should default back to the current directory).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started