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



c program which accept one argument as a directory name and prints all the file name along with it..

Answer / 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

More Shell Script Interview Questions

What is inside a seashell?

0 Answers  


How do I run a script from command prompt?

0 Answers  


How can you find out how long the system has been running?

0 Answers  


What is shell chemistry?

0 Answers  


Where cron file kept?

2 Answers   Tech Mahindra,






How to include comments in your shell scripts?

3 Answers  


What language is bash?

0 Answers  


Suppose you execute a command using exec, what will be the status of your current process in the shell?

0 Answers  


What are the different communication commands available in the shell?

0 Answers  


Set up a Sev 2 alert when the Primary WA service fails. A windows batch script needs to be created that will monitor the WA service on the Primary and when the service stops/fails a Sev 2 TT is generated for a particular team ?

0 Answers   TCS,


What is the need of including script interpreter in your shell script?

2 Answers  


Explain about gui scripting?

0 Answers  


Categories