-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_file_dir.cpp
67 lines (66 loc) · 2.28 KB
/
create_file_dir.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
/*============================================================
@author - Rushitkumar Jasani @rollno - 2018201034
=============================================================*/
#ifndef MYHEADER_H
#define MYHEADER_H
#include "myheader.h"
#endif
#ifndef GLOBAL_H
#define GLOBAL_H
#include "global.h"
#endif
/*============================================================
create file at path provided by user.
user can create multiple files at time also.
eg : create_file <f1> <f2> <f3> <Destination Folder>
=============================================================*/
void create_file()
{
if (my_command.size() < 3)
printf("too few arguments:\n");
else {
string dest_folder = create_absolute_path(my_command[my_command.size() - 1]);
//verifies if destination is directory or not.
if(!isDirectory(dest_folder)){
cout << "Destination is not directory" << endl;
return;
}
FILE* file_create;
for (unsigned int i = 1; i < my_command.size() - 1; i++) {
string dest_path = dest_folder + "/" + my_command[i];
file_create = fopen(dest_path.c_str(), "w+");
if (file_create == NULL)
perror("");
else
cout << "file created" << endl;
fclose(file_create);
}
}
return;
}
/*============================================================
create directory at path provided by user.
user can create multiple directory at a time also.
eg : create_dir <d1> <d2> <d3> <Destination Folder>
=============================================================*/
void create_dir()
{
if (my_command.size() < 3)
printf("too few arguments\n");
else {
string dest_folder = create_absolute_path(my_command[my_command.size() - 1]);
//verifies if destination is directory or not.
if (!isDirectory(dest_folder)) {
cout << "Destination is not directory." << endl;
return;
}
for (unsigned int i = 1; i < my_command.size() - 1; i++) {
string dest_path = dest_folder + "/" + my_command[i];
if (mkdir(dest_path.c_str(), 0755) != 0)
perror("");
else
cout << "directory created successfully." << endl;
}
}
return;
}