-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileRemover.cpp
38 lines (35 loc) · 995 Bytes
/
fileRemover.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
bool fileRemover(fs::directory_entry map) {
if(!map.exists()){
return false;
}
if(!map.is_directory()){
return fs::remove(map);
}
for (const fs::directory_entry& entry : fs::directory_iterator(map)) {
if (!entry.is_directory()) {
fs::remove(entry);
}else{
if(map != entry){
fileRemover(entry);
}
}
}
return fs::remove(map);
}
int main(int argc, char** args){
if(argc == 1){
std::cout << "usage: " << args[0] << " [directory/file names]\n";
exit(0);
}
for(int i = 1;i < argc;i++){
clock_t start = clock();
if(fileRemover(fs::directory_entry(args[i]))){
std::cout << "Succesfully deleted " << args[i] << std::endl;
}else{
std::cout << "Couldn't delete " << args[i] << std::endl;
}
}
}