Skip to content

Instantly share code, notes, and snippets.

@miketweaver

miketweaver/scandir.cpp

Last active May 24, 2020
Embed
What would you like to do?
UnRaid Filesystem Issues
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int
main(void)
{
struct dirent **namelist;
int n;
n = scandir("/mnt/user/games/GAMES/BLUS31606", &namelist, NULL, alphasort);
if (n < 0)
perror("scandir");
else {
while (n--) {
printf("\n%s, ", namelist[n]->d_name);
switch(namelist[n]->d_type) {
case DT_DIR:
printf("d_type: DT_DIR");
break;
case DT_UNKNOWN:
printf("d_type: DT_UNKNOWN");
break;
case DT_LNK:
printf("d_type: DT_LNK");
break;
case DT_FIFO:
printf("d_type: DT_FIFO");
break;
case DT_REG:
printf("d_type: DT_REG");
break;
default:
printf("d_type: other");
}
free(namelist[n]);
}
free(namelist);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
int
main(void)
{
struct dirent **namelist;
int n;
n = scandir("/mnt/user/games/GAMES/BLUS31606", &namelist, NULL, alphasort);
if (n < 0)
perror("scandir");
else {
while (n--) {
printf("%s, ", namelist[n]->d_name);
struct stat filestat;
stat(namelist[n]->d_name,&filestat);
if( S_ISDIR(filestat.st_mode) )
printf("unknown is a Directory!");
if( S_ISREG(filestat.st_mode) )
printf("unknown is a File!");
if( S_ISCHR(filestat.st_mode) )
printf("unknown is a CHR!");
if( S_ISFIFO(filestat.st_mode) )
printf("unknown is a FIFO!");
if( S_ISLNK(filestat.st_mode) )
printf("unknown is a LNK!");
free(namelist[n]);
printf("\n");
}
free(namelist);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.