<分区>
我正在编写一个代码,它获取其中包含 txt 文件的文件夹的目录,然后打印出创建/上次修改同一月份的所有 txt 文件。
例如,如果用户键入“JANUARY”,程序将打印出在一月份创建/最后修改的所有文件的名称。
这是我的代码,但它不起作用。
DIR *da;
struct dirent *ep;
struct stat attrib;
da = opendir ("./");
if (da != NULL)
{
while (ep = readdir (da))
{
while ((ep = readdir (da)) != NULL)
{
const size_t len = strlen(ep->d_name);
if (len > 4 &&
ep->d_name[len - 4] == '.' &&
ep->d_name[len - 3] == 'T' &&
ep->d_name[len - 2] == 'X' &&
ep->d_name[len - 1] == 'T') {
stat(ep->d_name, &attrib);
strftime(month, MAX_SIZE, "%m", localtime(&(attrib.st_ctime)));
comp = strcmp(month,input);
if(comp == 0) {
printf ("%s\n", ep->d_name);
}
}
}
closedir (da);
}
}