-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_dir.cpp
More file actions
39 lines (35 loc) · 917 Bytes
/
copy_dir.cpp
File metadata and controls
39 lines (35 loc) · 917 Bytes
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
39
#include <unistd.h>
#include <dirent.h>
#include <cstring>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
void removedir(char * dir){
DIR *dp;
struct dirent * entry;
struct stat statbuff;
if((dp = opendir(dir))!=NULL){
chdir(dir);
while((entry = readdir(dp))!=NULL){
lstat(entry->d_name, &statbuff);
if(S_ISDIR(statbuff.st_mode)){
if((strcmp(".", entry->d_name)==0) || strcmp("..", entry->d_name)==0){
continue;
}
removedir(entry->d_name);
}
remove(entry->d_name);
}
chdir("..");
rmdir(dir);
}
}
int main(int argc, char const *argv[])
{
char * folderlocation;
strcpy(folderlocation, argv[1]);
cout << "Cleaning directory " << argv[1] << endl;
removedir(folderlocation);
return 0;
}