본문 바로가기
IT/C++

How to perform chmod recursively?

by Spring Up!! 2023. 12. 19.
반응형

출처: https://stackoverflow.com/questions/71249234/how-to-perform-chmod-recursively

#include <iostream>

#include <filesystem>            // see notes about these two lines at the bottom
namespace fs = std::filesystem;  // -"-

void chmodr(const fs::path& path, fs::perms perm) {
    fs::permissions(path, perm);      // set permissions on the top directory
    for(auto& de : fs::recursive_directory_iterator(path)) {
        fs::permissions(de, perm);    // set permissions
        std::cout << de << '\n';      // debug print
    }
}

int main() {
    chmodr("your_top_directory", fs::perms::all); // perms::all = 0777
}
반응형

댓글