-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_delete_files.cpp
More file actions
91 lines (80 loc) · 2.66 KB
/
create_delete_files.cpp
File metadata and controls
91 lines (80 loc) · 2.66 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/************************************************************************
** RollNo:2018201033 Name : Darshan Kansagara **
************************************************************************/
#include "myheader.h"
//**********************************************************************
// This function is to remove single file
//**********************************************************************
void removeSingleFile(char *path)
{
//cout<<"path for deleting file : "<<path<<endl;
int status= remove(path);
if(status != 0)
{
showError("Error in removing the File with path ::::: "+string(path));
}
}
//**********************************************************************
// It removes multiple files that passed by User in argument
//**********************************************************************
void removeFiles(vector<string> list)
{
if(list.size()<2)
{
showError("Less number of Argument in delete_file command");
}
for(unsigned int i=1;i<list.size();i++)
{
char *path = new char[list[i].length() + 1];
strcpy(path, list[i].c_str());
removeSingleFile(path);
}
}
//**********************************************************************
// This Function used to create file in given path
//**********************************************************************
void createSingleFile(char *path)
{
//cout<<"\ncreateSingleFile path : "<<path<<endl;
int status=open(path,O_RDONLY | O_CREAT,S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
if (status == -1)
{
showError("Error in creating new file path ::::: " + string(path));
}
}
//**********************************************************************
// This function is used to create multiple files as given by user
//**********************************************************************
void createNewFiles(vector<string> list)
{
if(list.size() < 3)
{
showError("Less Number of Argument in Renaming !!!");
return ;
}
unsigned int len=list.size();
string destpath= pathProcessing(list[len-1]);
//cout<<"\ndestpath : "<<destpath<<endl;
for(unsigned int i=1;i<len-1;i++)
{
string fileName = destpath + "/" + list[i];
char *path = new char[fileName.length() + 1];
strcpy(path, fileName.c_str());
createSingleFile(path);
}
}
//**********************************************************************
// This Function rename the file/Dir
//**********************************************************************
void renameFiles(vector<string> list)
{
if(list.size()!=3)
{
showError("Invalid Argument in Renaming !!!");
}
else{
string initName = list[1];
string finalName = list[2];
rename(initName.c_str(),finalName.c_str());
}
}