1 /* Recursively descend the filesystem and visit each file. */
16 void scandir(const string& path);
18 void scanfile(const string& path)
21 lstat(path.c_str(), &stat_buf);
23 printf("%s:\n", path.c_str());
24 printf(" ino=%Ld, perm=%04o, uid=%d, gid=%d, nlink=%d, blksize=%d, size=%Ld\n",
25 (int64_t)stat_buf.st_ino, stat_buf.st_mode & 07777,
26 stat_buf.st_uid, stat_buf.st_gid, stat_buf.st_nlink,
27 (int)stat_buf.st_blksize, (int64_t)stat_buf.st_size);
29 switch (stat_buf.st_mode & S_IFMT) {
35 printf(" special file\n");
38 printf(" regular file\n");
41 printf(" directory\n");
47 void scandir(const string& path)
49 printf("Scan directory: %s\n", path.c_str());
51 DIR *dir = opendir(path.c_str());
54 printf("Error: %m\n");
59 while ((ent = readdir(dir)) != NULL) {
60 string filename(ent->d_name);
61 if (filename == "." || filename == "..")
63 printf(" d_name = '%s'\n", filename.c_str());
64 scanfile(path + "/" + filename);
70 int main(int argc, char *argv[])