2016-09-30 116 views
0

如何获取inode编号的文本文件的列表? in C打印C中的Inode编号

int main(int argc, char *argv[]) 
{ 

    FILE *pFile; 
    pFile=fopen("file.txt", "r"); 
     . 
     . 
     . 
     . 
    fclose(pFile); 

    system("pause"); 
    return 0; 
} 

我不知道如何得到inode。

添加人员代码?

+0

http://stackoverflow.com/questions/22575727/printing-info-of-a-file-director-inode –

+0

M.S乔杜里:如何指定哪些文件具有显示信息?将我的文件命名为file.txt。 – Henrix

回答

0

这是正确的?

int main (int argc, char *argv[]) 
{ 
    struct stat fileStat; 
    int fd=0; 
    FILE *filename = "infile.txt"; 

    if ((fd = open (filename , O_RDONLY)) == -1){ 
     perror ("open "); 
     system("pause"); 
     exit (1) ; 
    } 

    if(fstat(fd, &fileStat)<0) return 1; 

    printf("Information for %s\n",filename); 
    printf("---------------------------\n"); 
    printf("File Size: \t\t%d bytes\n",fileStat.st_size); 
    printf("Number of Links: \t%d\n",fileStat.st_nlink); 
    printf("File inode: \t\t%d\n",fileStat.st_ino); 

    system("pause"); 
    return 0; 
} 
0

希望这有助于!

#include <stdio.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <stdlib.h> 
int main (int argc, char *argv[]) 
{ 
     struct stat fileStat; 
     int fd=0; 
     FILE *filename = "file1.txt"; 

     if ((fd = open (filename , O_RDONLY)) == -1){ 
       perror ("open "); 
       system("pause"); 
       exit (1) ; 
     } 

     if(fstat(fd, &fileStat)<0) return 1; 

     printf("File inode: %d\n",fileStat.st_ino); 

     return 0; 
}