递归打印当前目录下所有的文件夹以及文件名
作者:
小小蒟蒻
,
2020-10-13 12:26:32
,
所有人可见
,
阅读 456
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <io.h>
#include <time.h>
using namespace std;
string path;
void DfsFolder()
{
_finddata_t file;
path += "/*";
long handle = 0;
if (-1L == (handle = _findfirst(path.c_str(), &file))) return;
do {
tm* pt = localtime(&file.time_write);
printf("%04d/%02d/%02d %02d:%02d ",
pt->tm_year + 1900, pt->tm_mon, pt->tm_mday, pt->tm_hour, pt->tm_min);
if (file.attrib & _A_SUBDIR) {
printf(" %-12s %-4s\n", "<DIR>", file.name);
if (strcmp(file.name, ".") && strcmp(file.name, "..")) {
path = path + '/' + file.name;
DfsFolder();
}
}
else printf(" %12u %-4s\n", file.size, file.name);
} while (!_findnext(handle, &file));
_findclose(handle);
}
int main(int argc, char* argv[]) {
printf("输入全路径的路径名:");
getline(cin, path, '\n');
DfsFolder();
return 0;
}