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 does chmod do?
What is the default shell of solaris?
Please give me example of " at command , contrab command " how to use
Write a script to print the first 10 elements of fibonacci series.
Can shell script run on windows?
In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?
c program which behaves like a shell(command interpreter). it has its own prompt say "NewShell$".any normal shell command is executed from your shell by starting a child process to execute a system program corrosponding to the command
How can we find the process name from its process id?
What is bourne shell scripting?
What are different types of shell?
What is the best scripting language?
How to calculate the number of passed arguments?
What is a shell script? Can you name some of its advantages?
Is shell scripting easy to learn?
What is the default ubuntu terminal?