c program which accept one argument as a directory name and
prints all the file name along with its inode number and
total count of the file in directory
Answer Posted / rakesh
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stddef.h>
#include <sys/stat.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dip;
struct dirent *dit;
struct stat sb;
int i = 0;
if(argc < 2)
{
printf("Usage: %s <directory>\n", argv[0]);
return 0;
}
if((dip = opendir(argv[1])) == NULL)
{
perror("opendir");
return 0;
}
printf("Directory stream is now open\n");
while ((dit = readdir(dip)) != NULL)
{
i++;
stat(dit->d_name,&sb);
printf("%u \t%s\n",sb.st_ino,dit->d_name);
}
printf("No. of Files in directory are: %i \n", i);
if(closedir(dip)== -1)
{
perror("closedir");
return 0;
}
printf("\nDirectory stream is now closed\n");
return 1;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is a program shell?
What is the significance of the shebang line in shell scripting?
how to print the matrix form of 2-d, 3-d arrays in unix c shell scripts ?
What does $0 mean in shell script?
How to get the last line from a file using just the terminal?
write a shell script to check the failed jobs?
How do I save a powershell script?
what is tickets $ what low,medium,high priorite pls define time also
What are the different types of shell scripting?
Determine the output of the following command: [ -z “” ] && echo 0 || echo 1
What is the use of a shebang line?
What does sh mean?
Is shell a scripting language?
What command needs to be used to take the backup?
Explain about non-login shell files?