-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra_utility.cpp
73 lines (67 loc) · 1.92 KB
/
extra_utility.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
68
69
70
71
72
73
/************************************************************************
** RollNo:2018201033 Name : Darshan Kansagara **
************************************************************************/
//**********************************************************************
// Header file Included
//**********************************************************************
#include "myheader.h"
//**********************************************************************
// Function to handle goto Directory Part
//**********************************************************************
string gotoPath(vector<string> list)
{
string str="";
if(list.size()!=2)
{
showError("Invalid Argument in Goto");
}
else{
str= list[1];
}
return str;
}
//**********************************************************************
// This Function returns whether given path is of directory or file
//**********************************************************************
int isdirectory(char *newpath)
{
struct stat sb;
if (stat(newpath,&sb) == -1) {
perror("lstat");
}
else
{
if((S_ISDIR(sb.st_mode)))
{
return 1;
}
else
{
return 0;
}
}
return -1;
}
//**********************************************************************
// This Function extract filename from its full path
//**********************************************************************
string getFileNameFromPath(string newData)
{
string name;
size_t pos;
pos = newData.find_last_of("/\\");
name = newData.substr(pos+1,newData.length());
//cout<<"\nfilename : "<<name;
return name;
}
//**********************************************************************
// This Function used to display error in Red Formate
//**********************************************************************
void showError(string str)
{
//clearCommand();
cout<<endl;
cout<<"\033[0;31m"<<str<<endl;
cout<<"\033[0m";
cout<<":";
}