我是C语言编程的新手.我需要这个程序遍历文件夹中的所有文件并为每个文件打印这些属性.此时它正在打印文件夹的属性.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct stat file_stats;
if (argc != 2) {
fprintf(stderr, "Usage: fstat FILE...\n");
return EXIT_FAILURE;
}
if ((stat(argv[1], &file_stats)) == -1) {
perror("fstat");
return EXIT_FAILURE;
}
dp = opendir("./");
if (dp == NULL) {
perror("couldn't open directory");
return EXIT_FAILURE;
}
while (readdir(dp)) {
printf("filename: %s\n", argv[1]);
printf(" device: %lld\n",
file_stats.st_dev);
printf(" protection: %o\n",
file_stats.st_mode);
printf(" number of hard links: %d\n", …Run Code Online (Sandbox Code Playgroud)