-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.cpp
More file actions
60 lines (50 loc) · 1.65 KB
/
files.cpp
File metadata and controls
60 lines (50 loc) · 1.65 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
#include <dirent.h>
#include <sys/stat.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <string>
using namespace std;
/*
All our files will be stored in the /var/lib/deadline directory
of delenn so they can be accessed easily by the user
This code will list all the files present in the directory
to help keep list of what we have
Attempting to change the file permissions of all files in the
directory to allow rwx permissions for group members and file
owners
*/
void open(char *dir_name)
{
DIR *dir; // pointer to directory
struct dirent *component; // directory contents
struct stat info; // info about components (files)
int chmod(const char *dir_name, mode_t mode);
dir = opendir(dir_name); // open directory
if(!dir)
{
cout << "\nDirectory Not Found\n" << endl;
return;
}
// read
while((component = readdir(dir)) != NULL)
{
if(component->d_name[0] != '.')
{
string path = string(component->d_name);
cout << "File: " << path << "\t \t \t***in directory" << ": " << string(dir_name) << endl;
stat(path.c_str(), &info); // get information from this path
if(S_ISDIR(info.st_mode))
{
open((char*)path.c_str());
chmod(path.c_str(), S_IRWXO);
}
}
}
closedir(dir);
}
int main()
{
open((char*) "/var/lib/deadline");
return 0;
}