Question: Objective : File System Management. We want to develop a program called dirtree [ ] that lists the name of the FILEs (the current directory

Objective: File System Management.

We want to develop a program called dirtree [] that lists the name of the FILEs (the current directory by default) in the path directory. If one entry in the directory is also a directory all the files in that directory will be also listed but one TAB right (and so on for any directories level).

You will have to use the following functions:

#include #include DIR *opendir(const char *name);

The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. The stream is positioned at the first entry in the directory.

#include struct dirent *readdir(DIR *dirp);

The readdir() function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointedto by dirp. It returns NULL on reaching the end of the directory stream or if an error occurred.

The dirent structure is defined as follows:

struct dirent {

 ino_t d_ino; 
/* Inode number */ /* Not an offset; see below */ /* Length of this record */ /* Type of file */ 

};

off_t d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; /* Null-terminated filename */ 

#include #include int closedir(DIR *dirp);

The closedir() function closes the directory stream associated with dirp. A successful call to closedir() also closes the underlying file descriptor associated with dirp. The directory stream descriptor dirp is not available after this call.

Execution example:

$ dirtree ~/cse278 .. examples 
 datas.c hello.c .. prtFunc.c prep.c compile solPrep.c structs . 
 types prep types.c hello prtFunc myProgram.c myheader.h prep2 solPrep prep2.c myProgram datas structs.c 

lab1 ..

 compile . pwd.txt hello 

. hello.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!