major changes

fs_reader now fully works
header file has new file extension
This commit is contained in:
AustrianToast 2024-02-16 23:01:18 +01:00
parent f619b37126
commit c437168ee9
No known key found for this signature in database
GPG Key ID: 5CD422268E489EB4
5 changed files with 3759 additions and 35 deletions

View File

@ -1,39 +1,81 @@
#include <iostream>
#include "fs_reader.h"
#include <vector>
#include <filesystem>
#include <queue>
#include "fs_reader.hpp"
namespace fs = std::filesystem;
using std::vector, std::queue;
// from the provided path, find all files and folders
// This is done by finding all the files and folders in the starting dir
// If a dir was found, then go into it, then find all files and folders in there
// Rinse and Repeat
int validate(const fs::path path) {
if(!fs::exists(path))
return 1;
// Avoid recursion if possible
std::vector<fs::path> find_all_files(fs::path path) {
std::vector<fs::path> files = {};
if (false)
return 1;
for (const fs::directory_entry &entry : fs::directory_iterator(path))
if (!entry.is_directory())
files.insert(files.begin()+files.size(), entry.path());
return 0;
}
vector<fs::path> find_all_files(const fs::path path) {
if (validate(path) == 1)
return vector<fs::path>(0);
vector<fs::path> files;
queue<fs::path> folders_to_traverse;
folders_to_traverse.push(path);
while (!folders_to_traverse.empty()) {
for (const fs::directory_entry &entry : fs::directory_iterator(folders_to_traverse.front()))
if (!entry.is_directory())
files.emplace_back(entry);
else
folders_to_traverse.push(entry);
folders_to_traverse.pop();
}
files.shrink_to_fit();
return files;
}
std::vector<fs::path> find_all_folders(fs::path path) {
std::vector<fs::path> folders = {};
vector<fs::path> find_all_folders(const fs::path path) {
if (validate(path) == 1)
return vector<fs::path>(0);
for (const fs::directory_entry &entry : fs::directory_iterator(path))
if (entry.is_directory())
folders.insert(folders.begin()+folders.size(), entry.path());
vector<fs::path> folders;
queue<fs::path> folders_to_traverse;
folders_to_traverse.push(path);
while (!folders_to_traverse.empty()) {
for (const fs::directory_entry &entry : fs::directory_iterator(folders_to_traverse.front()))
if (entry.is_directory()) {
folders.emplace_back(entry);
folders_to_traverse.push(entry);
}
folders_to_traverse.pop();
}
folders.shrink_to_fit();
return folders;
}
std::vector<fs::path> find_all_files_and_folders(fs::path path) {
std::vector<fs::path> files_and_folders = {};
vector<fs::path> find_all_files_and_folders(const fs::path path) {
if (validate(path) == 1)
return vector<fs::path>(0);
for (const fs::directory_entry &entry : fs::directory_iterator(path))
files_and_folders.insert(files_and_folders.begin()+files_and_folders.size(), entry.path());
vector<fs::path> files_and_folders;
queue<fs::path> folders_to_traverse;
folders_to_traverse.push(path);
while (!folders_to_traverse.empty()) {
for (const fs::directory_entry &entry : fs::directory_iterator(folders_to_traverse.front())) {
files_and_folders.emplace_back(entry);
if (entry.is_directory())
folders_to_traverse.push(entry);
}
folders_to_traverse.pop();
}
files_and_folders.shrink_to_fit();
return files_and_folders;

View File

@ -1,8 +0,0 @@
#include <string>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
std::vector<fs::path> find_all_files(fs::path path);
std::vector<fs::path> find_all_folders(fs::path path);
std::vector<fs::path> find_all_files_and_folders(fs::path path);

6
src/fs_reader.hpp Normal file
View File

@ -0,0 +1,6 @@
#include <vector>
#include <filesystem>
std::vector<std::filesystem::path> find_all_files(const std::filesystem::path path);
std::vector<std::filesystem::path> find_all_folders(const std::filesystem::path path);
std::vector<std::filesystem::path> find_all_files_and_folders(const std::filesystem::path path);

View File

@ -1,24 +1,28 @@
#include <iostream>
#include "fs_reader.h"
#include <vector>
#include <filesystem>
#include "fs_reader.hpp"
namespace fs = std::filesystem;
using std::cout, std::vector;
int main(int argc, char *argv[]) {
if (argc == 1) {
std::cout << "chksum: No path specified\n";
cout << "chksum: No path specified\n";
return 1;
}
if (argc > 2) {
std::cout << "chksum: Too many arguments\n";
cout << "chksum: Too many arguments\n";
return 1;
}
if (!fs::exists(argv[1])) {
std::cout << "chksum: Not a valid path\n";
cout << "chksum: Not a valid path\n";
return 1;
}
std::vector<fs::path> files_and_folders = find_all_files_and_folders(argv[1]);
vector<fs::path> files_and_folders = find_all_files(argv[1]);
for (size_t index = 0; index < files_and_folders.size(); index++)
std::cout << "index " << index << ": " << files_and_folders.at(index) << std::endl;
for (const fs::path &path : files_and_folders)
cout << path << "\n";
return 0;
}

3680
test Normal file

File diff suppressed because it is too large Load Diff