Ход работы
5. Написать программу вывода иерархического списка всех вложенных каталогов, начиная с указанного. Формат вызова программы: catlist <путь>. Программа должна выводить иерархический список каталогов по строкам: в первой строке — корневой каталог, во второй — его подкаталоги, далее — их подкаталоги и т.д.
Текст программы
#include <iostream>
#include <dirent.h>
#include <string>
#include <vector>
#include <memory>

using namespace std;

template<typename T>
using TArray = std::vector<T>;
using TString = std::string;
using TStringList = std::vector<TString>;
using PDirectoryNode = std::unique_ptr<struct DirectoryNode>;

struct DirectoryNode
{
    TString                  path;
    TString                  dirName;
    TArray<DirectoryNode>    childs;
    ~DirectoryNode()
    {
        childs.clear();
    }
};

using TDirecytoryTree = std::vector<struct DirectoryNode *>;

DirectoryNode getDirectoryNode(TString path, TString dirName)
{
    DirectoryNode node;


    auto fullName = path + "/" + dirName;
    auto dir = opendir(fullName.c_str());

    if(dir == nullptr)
    {
        std::cout << "Can't open dir: " << fullName << std::endl;
        return {};
    }

    node.dirName = dirName;
    node.path = path;

    auto entity = readdir(dir);
    while(entity != nullptr)
    {
        //Parse dir
        {
            if(entity->d_type == DT_DIR)
            {
                if(entity->d_name[0] != '.')
                {
                    TString subName(entity->d_name);
                    auto n = getDirectoryNode(fullName+"/",subName);
                    node.childs.push_back(n);
                }
            }
            else if(entity->d_type == DT_REG)
            {
                //With file
            }
        }
        //Get other entity
        entity = readdir(dir);
    }

    closedir(dir);

    return node;
}


void print(TDirecytoryTree tree)
{
    TDirecytoryTree subtree;
    for(const auto &i : tree)
    {
        std::cout << i->dirName << ", ";
        for(auto &j : i->childs)
            subtree.push_back(&j);
    }
    std::cout << std::endl;
    if(subtree.size() != 0)
        print(subtree);
}



int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        if(argc < 2)
            std::cout << "Мало параметров" << std::endl;
        else
            std::cout << "Много параметров" << std::endl;
        return -1;
    }

    TString str = TString(argv[1]);
    if(str.size() == 0)
    {
        //TODO: Error
        return -1;
    }

    std::size_t found = str.find_last_of("/\\");
    auto path = str.substr(0,found);
    auto name = str.substr(found+1);

    auto node = getDirectoryNode(path, name);
    print({&node});



    return 0;
}
