Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions