Wednesday, 20 February 2013

Program:To write a c program to list inode number and filename for every file in a directory

Program:To write a c program to list  inode number and filename for every file in a directory

#include
#include
#include
#include
#include
#include
main()
{
DIR *dp;
struct dirent *p;
char dname[20];
struct stat x;
printf("Enter the directory name:");
scanf("%s",dname);
dp=opendir(dname);
printf("\n FILE NAME\t INODE NUMBER\n");
while((p=readdir(dp))!=NULL)
{
printf("%s\t      %ld\n",p->d_name,x.st_ino);
}
}





/*--------------------------INPUT/OUTPUT-------------------


-bash-3.2$ cc inode.c -o inode
-bash-3.2$ ./inode
Enter the directory name:lunix

 FILE NAME       INODE NUMBER
..                 4195164
file2.c            4195164
.                  4195164
file1.c            4195164


-------------------------------------------------------*/

1 comment: