This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
struct dirent ** x = NULL;
int n = scandir (p, &x, NULL, alphasort);
scandir allocates memory and returns the number of entries. each entry must be free'd. See also opendir, readdir and closedir and ftw for recursive traversal.
auto directory_contents(auto path) {
auto iterator = std::filesystem::directory_iterator(path);
return std::vector<std::filesystem::path>(
std::ranges::begin(iterator),
std::ranges::end(iterator)
);
}
auto main(int argc, char** argv) -> int {
auto path = argc >= 2
? std::filesystem::path(argv[1])
: std::filesystem::current_path();
for (auto entry : directory_contents(path)) {
std::cout << entry.string() << std::endl;
}
}
auto x = dirEntries(d, SpanMode.shallow);
dirEntries is lazy and supports many traversal strategies.
final File directory = new File(d);
final File[] x = directory.listFiles();