-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletedir.h
66 lines (57 loc) · 1.67 KB
/
deletedir.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include<bits/stdc++.h>
//#include"copy.h"
using namespace std;
void deletedir(char *dir)
{
//char * g="hello";
//printf("hello %s\n",g);
//printf("wd=%s\n",wd);
DIR *dp,*desti;
struct dirent *entry,*entry1;
struct stat statbuf;
if((dp = opendir(dir)) == NULL)
{
fprintf(stderr,"cannot open directory: %s\n", dir);
return;
}
dp=opendir(dir);
//desti=opendir(wd);
//chdir(wd);
chdir(dir);
//entry1=readdir(desti);
//cout<<"outside"<<endl;
while((entry = readdir(dp)) != NULL)
{
// cout<<"hello"<<endl;
lstat(entry->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode))
{
if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0)
continue;
//cout<<endl;
char *h=convert(dir,entry->d_name);
//cout<<"helllllll "<<h<<endl;
//char *h1=convert(wd,entry1->d_name);
//cout<<"wd "<<wd<<endl;
//char * r=mkdir1(h,wd);
deletedir(h);
rmdir(h);//remove directory sub
}
else
{
remove(entry->d_name);
}
}
rmdir(dir);
//chdir("..");//for new
chdir("..");
//closedir(desti);
//closedir(dp);
}
//////////////////////////folder add done///////////////////////////////////////////////////////////////////////