/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-1005-008/main.cpp
35 строк
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
#include <iostream> #include <filesystem> #include <string> namespace fs = std::filesystem; void scanDirectory(const fs::path& path, int indent = 0) { for (const auto& entry : fs::directory_iterator(path)) { std::string prefix(indent, ' '); if (entry.is_directory()) { std::cout << prefix << "[DIR] " << entry.path().filename() << std::endl; scanDirectory(entry.path(), indent + 2); } else { auto size = entry.file_size(); std::cout << prefix << "[FILE] " << entry.path().filename() << " (" << size << " байт)" << std::endl; } } } int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "Использование: " << argv[0] << " <путь_к_директории>" << std::endl; return 1; } fs::path targetPath(argv[1]); if (!fs::exists(targetPath) || !fs::is_directory(targetPath)) { std::cerr << "Указанный путь не существует или не является директорией." << std::endl; return 1; } scanDirectory(targetPath); return 0; }