Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, you need only write a single-file C program. Your program will: Obtain a root directory (relative to current working directory or absolute

For this assignment, you need only write a single-file C program. Your program will:

Obtain a root directory (relative to current working directory or absolute path), and a minimum size match size (in bytes) from the command line. The root directory will serve as the starting point of a recursive search for regular files of size at least match size, in root and all nested directories.

Use the function defined below to compute and return the number of such regular files in the given root directory and all nested directories; As well as to display each qualifying file name (which includes the relative path from root to the file) and its size to the screen (as they are discovered).

Then display the computed count to the screen.

In other words you are writing a program somewhat like ls but instead of displaying names and various attributes of everything in one given directory, it displays only the names (with relative paths to a given root directory) and sizes of regular files that are at least the given (match size) - in the entire directory sub-tree rooted by the specified directory (root) and indicated the total number of such files.

Write a (separate) recursive function that:

Given a root directory, computes (and returns) the number of regular files in that directory whose file sizes are at least match size, added to the result of this function recursively called on each directory file (sub-directory) in that directory. Note: as each qualifying file is discovered, you must display (to the screen) the file's name (post-pended to the current relative path from root to the directory where you found the file) and the file's size, as well as increment a counter.

Clearly the base case for this recursion is when a given root directory has no sub-directories.

Note: you must never recurse on the following two directories:

. current directory

.. parent directory

And in general we will say that you do not need to recurse on any hidden directories those that start with a period [ . ] ( shown byls -a but not ls ). If you would like a challenge you could take a second command line parameter (+h or -h) which decides if hidden directories are included or not.

Sample Run:

% ./myls . 1024

./andy.txt 12345

./subdir/band.out 786504

./subdir/cs337/handy.c 1024

./than.tex 4985

4 Matching files in all

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions