/*
enum
{
DT_UNKNOWN = 0, //未知类型
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1, //管道
# define DT_FIFO DT_FIFO
DT_CHR = 2, //字符设备
# define DT_CHR DT_CHR
DT_DIR = 4, //目录
# define DT_DIR DT_DIR
DT_BLK = 6, //块设备
# define DT_BLK DT_BLK
DT_REG = 8, //常规文件
# define DT_REG DT_REG
DT_LNK = 10, //符号链接
# define DT_LNK DT_LNK
DT_SOCK = 12, //套接字
# define DT_SOCK DT_SOCK
DT_WHT = 14 //链接
# define DT_WHT DT_WHT
};
*/
#define LOG_DIR “/iot/log”
#define FILENAME_LOG ".log"
void print_dir_files(void)
{
DIR *dir_fd = NULL;
struct dirent *dir_ptr = NULL;
if ((dir_fd = opendir(LOG_DIR)) != NULL) {
while ((dir_ptr = readdir(dir_fd)) != NULL) {
//判断是文件
if (dir_ptr->d_type == 8) {
printf("this is a file[%d]: %s\r\n", strlen(dir_ptr->d_name),\
dir_ptr->d_name);
#if 1
//删除非法文件
if (strlen(dir_ptr->d_name) != 12 \
|| (strstr(dir_ptr->d_name, FILENAME_LOG) == NULL)) {
memset(namebuf, 0, sizeof(namebuf));
sprintf(namebuf, "%s/%s", MEIGE_LOG_DIR, dir_ptr->d_name);
printf"remove file[%d]: %s\n", strlen(dir_ptr->d_name), namebuf);
//remove(namebuf);
}
#endif
}
}
}
closedir(dir_fd);
}