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 [
You will have to use the following functions:
#include
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
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
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
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