fs_reader mostly works
slight changes to datatypes and return values is able to print out all files and folders in specified directory
This commit is contained in:
parent
60aac542cd
commit
76d12f91b1
@ -10,24 +10,41 @@ namespace fs = std::filesystem;
|
|||||||
// Rinse and Repeat
|
// Rinse and Repeat
|
||||||
|
|
||||||
// Avoid recursion if possible
|
// Avoid recursion if possible
|
||||||
std::vector<std::string> find_all_files(std::string filesystem_path) {
|
std::vector<fs::path> find_all_files(std::string filesystem_path) {
|
||||||
for (const auto & entry : fs::directory_iterator(filesystem_path)) {
|
std::vector<fs::path> files = {"test"};
|
||||||
std::cout << entry.path() << "\n";
|
|
||||||
|
for (const fs::directory_entry & entry : fs::directory_iterator(filesystem_path)) {
|
||||||
|
if (entry.is_directory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
files.insert(files.begin()+files.size(), entry.path());
|
||||||
}
|
}
|
||||||
return std::vector<std::string>(0) = {};
|
|
||||||
|
files.shrink_to_fit();
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> find_all_folders(std::string filesystem_path) {
|
std::vector<fs::path> find_all_folders(std::string filesystem_path) {
|
||||||
return std::vector<std::string>(0) = {};
|
std::vector<fs::path> folders = {};
|
||||||
|
|
||||||
|
for (const fs::directory_entry & entry : fs::directory_iterator(filesystem_path)) {
|
||||||
|
if (entry.is_directory()) {
|
||||||
|
folders.insert(folders.begin()+folders.size(), entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
folders.shrink_to_fit();
|
||||||
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> find_all_files_and_folders(std::string filesystem_path) {
|
std::vector<fs::path> find_all_files_and_folders(std::string filesystem_path) {
|
||||||
std::vector<std::string> files = find_all_files(filesystem_path);
|
std::vector<fs::path> files = find_all_files(filesystem_path);
|
||||||
std::vector<std::string> folders = find_all_folders(filesystem_path);
|
std::vector<fs::path> folders = find_all_folders(filesystem_path);
|
||||||
std::vector<std::string> files_and_folders = {};
|
std::vector<fs::path> files_and_folders = {};
|
||||||
|
|
||||||
files_and_folders.reserve(files.size() + folders.size());
|
files_and_folders.reserve(files.size() + folders.size());
|
||||||
files_and_folders.insert( files_and_folders.end(), files.begin(), files.end() );
|
files_and_folders.insert( files_and_folders.end(), files.begin(), files.end() );
|
||||||
files_and_folders.insert( files_and_folders.end(), folders.begin(), folders.end() );
|
files_and_folders.insert( files_and_folders.end(), folders.begin(), folders.end() );
|
||||||
|
|
||||||
return std::vector<std::string>(0) = {};
|
return files_and_folders;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <filesystem>
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::vector<std::string> find_all_files(std::string filesystem_path);
|
std::vector<fs::path> find_all_files(std::string filesystem_path);
|
||||||
std::vector<std::string> find_all_folders(std::string filesystem_path);
|
std::vector<fs::path> find_all_folders(std::string filesystem_path);
|
||||||
std::vector<std::string> find_all_files_and_folders(std::string filesystem_path);
|
std::vector<fs::path> find_all_files_and_folders(std::string filesystem_path);
|
@ -1,7 +1,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include "fs_reader.h"
|
#include "fs_reader.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
(void)find_all_files_and_folders(argv[1]);
|
std::vector<fs::path> files_and_folders = find_all_files_and_folders(argv[1]);
|
||||||
|
|
||||||
|
for (size_t index = 0; index < files_and_folders.size(); index++) {
|
||||||
|
std::cout << "index " + std::to_string(index) + ": " + files_and_folders.at(index).string() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
files_and_folders.clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user