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

How do I save a powershell script?

0 Answers  


What are the different types of shell scripting?

0 Answers  


What is path variable bash?

0 Answers  


Create a bash shell script that removes all files whose names end with a "~" from your home directory and subdirectories. Name this script "cleanup.sh"

6 Answers  


Hello all, This is my assignment on shell scripting, can anyone help me regarding this ? Create a shell script which connects to the database In second shell script include the first script for the DB connection Create a table (PRADEEP_DATA) with 2 columns (name, value) In Third shell script include the first script for the DB connection And insert/delete the values from the Table, by accepting input from the user This functionality should be a menu driven Program: 1) Insert to the database a. Name b. value 2)Delete from the database a.Name b.value Exception handling needs to be taken care.

0 Answers   Cap Gemini, Wipro,






determine the output of the following command: echo ${new:-variable}

0 Answers  


what are bootlevel in linux?which level is booting by default.

5 Answers   Symphony,


Is bash a shell script?

0 Answers  


How will you list only the empty lines in a file (using grep)?

4 Answers   ANZ,


How to know that your remote server is ruing smoothly or not in unix?

1 Answers  


RAM one table colums a1,a2,a3,a4 respective values 2,4,7,8 KRISH one table colums a1,a2,a3,a4 respective values 3,4,6,9 IN RAM & KRISH a4 column if comparing values RAM A4 - KRISH A4 ( 8-9 =1 THEN print 5 or (RAM) a4 value 10 KRISH a4 values 2 then 10 -2 =8 print 5*8=40 or diff 5 print same

1 Answers   Tech Mahindra,


What is meant by dos operating system?

0 Answers  


Categories