small refactor
remove unnecessary curly braces and the clearing of vector
This commit is contained in:
parent
c292632545
commit
a44e53ee6a
@ -10,12 +10,9 @@
|
||||
std::vector<fs::path> find_all_files(fs::path path) {
|
||||
std::vector<fs::path> files = {};
|
||||
|
||||
for (const fs::directory_entry & entry : fs::directory_iterator(path)) {
|
||||
if (entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
files.insert(files.begin()+files.size(), entry.path());
|
||||
}
|
||||
for (const fs::directory_entry & entry : fs::directory_iterator(path))
|
||||
if (!entry.is_directory())
|
||||
files.insert(files.begin()+files.size(), entry.path());
|
||||
|
||||
files.shrink_to_fit();
|
||||
return files;
|
||||
@ -24,11 +21,9 @@ std::vector<fs::path> find_all_files(fs::path path) {
|
||||
std::vector<fs::path> find_all_folders(fs::path path) {
|
||||
std::vector<fs::path> folders = {};
|
||||
|
||||
for (const fs::directory_entry & entry : fs::directory_iterator(path)) {
|
||||
if (entry.is_directory()) {
|
||||
for (const fs::directory_entry & entry : fs::directory_iterator(path))
|
||||
if (entry.is_directory())
|
||||
folders.insert(folders.begin()+folders.size(), entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
folders.shrink_to_fit();
|
||||
return folders;
|
||||
@ -37,9 +32,8 @@ std::vector<fs::path> find_all_folders(fs::path path) {
|
||||
std::vector<fs::path> find_all_files_and_folders(fs::path path) {
|
||||
std::vector<fs::path> files_and_folders = {};
|
||||
|
||||
for (const fs::directory_entry &entry : fs::directory_iterator(path)) {
|
||||
for (const fs::directory_entry &entry : fs::directory_iterator(path))
|
||||
files_and_folders.insert(files_and_folders.begin()+files_and_folders.size(), entry.path());
|
||||
}
|
||||
|
||||
files_and_folders.shrink_to_fit();
|
||||
return files_and_folders;
|
||||
|
@ -20,10 +20,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
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;
|
||||
}
|
||||
for (size_t index = 0; index < files_and_folders.size(); index++)
|
||||
std::cout << "index " << index << ": " << files_and_folders.at(index) << std::endl;
|
||||
|
||||
files_and_folders.clear();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user