#include "unistd.h"
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
using namespace std;
#define USER_LIST_FILE "./UserInfo.txt"
#define USER_LIST_PHOTODIR "./user-photo"
void GetUserList()
{
FILE* fp = NULL;
DIR* pDir = NULL;
fp = fopen(USER_LIST_FILE,"r");
if (fp==NULL)
{
printf("file open fail \r\n");
return;
}
pDir = opendir(USER_LIST_PHOTODIR);
if (pDir==NULL)
{
printf("dir open fail \r\n");
return;
}
struct dirent *pDirent;
while((pDirent = readdir(pDir)) != NULL)
{
if (pDirent->d_type == DT_REG)//普通文件
{
}
printf("d_type:%d,d_name: %s\n",pDirent->d_type,pDirent->d_name);
}
}
int main()
{
GetUserList();
return 0;
}
结构体
/* File types for `d_type'. */
enum
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
};