Video Coming Soon...
34: ls
Implement the first command line tool, ls.
// https://www.gnu.org/software/coreutils/manual/html_node/ls-invocation.html
#include <fmt/core.h>
#include <filesystem>
namespace fs = std::filesystem;
int main(int argc, char* argv[]) {
for(int i = 1; i < argc; i++) {
fs::path target{argv[i]};
for(auto& dir_entry : fs::directory_iterator{target}) {
const std::string& path = dir_entry.path().filename().string();
if(!path.starts_with(".")) {
fmt::println("{}", path);
}
}
}
}
Register for Learn C++ the Hard Way
Register to gain access to additional videos which demonstrate each exercise. Videos are priced to cover the cost of hosting.