-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (28 loc) · 765 Bytes
/
main.cpp
File metadata and controls
33 lines (28 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cppcoro/recursive_generator.hpp>
#include <filesystem>
#include <iostream>
using namespace std;
using namespace cppcoro;
namespace fs = std::filesystem;
// 재귀적으로 파일 이름을 나열하는 제너레이터
auto list_files(const fs::path& dir) -> recursive_generator<fs::path>
{
for (auto& entry : fs::directory_iterator(dir))
{
if (entry.is_directory())
co_yield list_files(entry.path());
else if (entry.is_regular_file())
co_yield fs::path(entry.path());
}
}
int main()
{
fs::path root = "."; // 현재 디렉터리 기준
int count = 0;
for (auto& file : list_files(root))
{
cout << file.string() << "\n";
if (++count >= 20) break; // 처음 20개 파일만 출력
}
return 0;
}