-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.cpp
67 lines (66 loc) · 1.99 KB
/
move.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
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
67
//2018201005 Vatsal Soni
#include "config.h"
int moveFile(vector<string> &commandSplit) // It accepts arg from commandFile and move file/dir
{
string destination=commandSplit[commandSplit.size()-1];
vector<string> v;
for(unsigned i=1;i<commandSplit.size()-1;i++)
{
v.clear();
v.push_back("copy");
v.push_back(commandSplit[i]);
v.push_back(destination);
copyFile(v);
struct stat statObj;
char *ss=new char[commandSplit[i].length()+1];
strcpy(ss,commandSplit[i].c_str());
if(stat(ss,&statObj) < 0)
{
cout<<endl<<"No such directory exist"<<endl;
//return 1;
}
if(S_ISDIR(statObj.st_mode))
{
v.clear();
v.push_back("delete");
v.push_back(commandSplit[i]);
vector<string> ans=deleteDir(v);
if(ans.size()>0)
{
//cout<<endl<<endl;
for(int j=ans.size()-1;j>=0;j--)
{
//cout<<vc[i]<<endl;
char *p=new char[ans[j].length()+1];
strcpy(p,ans[j].c_str());
struct stat statObj;
stat(p,&statObj);
if(S_ISDIR(statObj.st_mode))
{
vector<string> v;
v.clear();
v.push_back("abc");
v.push_back(ans[j]);
deleteDir(v);
}
else
{
vector<string> v;
v.clear();
v.push_back("abc");
v.push_back(ans[j]);
deleteFile(v);
}
}
}
}
else
{
v.clear();
v.push_back("delete");
v.push_back(commandSplit[i]);
deleteFile(v);
}
}
return 0;
}