I am working on a project to create a database of files that I have in the current directory. And one of the details I need about my files is the rights to the files that are installed using chmod in ubuntu. (just a note: I will also need information about the group and owner - for example, chown - and if you can tell me if boost can get information about the owner, that would be great.)
I use the extended file system library and I checked the documentation many times, but could not find how to get permissions.
On this page, it shows that there enum perms, which has lines of file permissions that are not displayed on my own .hpp file system, (And I checked that I have version 1.49, also built from the source, to be sure ) Also on the same page here shows that he can get permissions, such as:
perms permissions() const noexcept;
I could not find the permissions function or the place where it stores the perms list.
This is the code that I still have (this is actually from the tutorials, but I changed it to recursive), if you could tell me how to get permissions / file owners or suggest a different library than increase. I would appreciate it.
EDIT: s.permissions(), ethan_liou , , . .
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <boost/filesystem.hpp>
#include <stdio.h>
using namespace std;
using namespace boost::filesystem;
int read(path p);
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut4 path\n";
return 1;
}
path p (argv[1]);
read(p);
return 0;
}
int read(path p) {
try
{
if (exists(p))
{
if (is_symlink(p)) {
cout << p << " is a link\n";
}
else if (is_regular_file(p)) {
file_status s = status(p);
cout << p << " size is " << file_size(p) << " perms " << "" ;
printf("%o\n",s.permissions());
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
typedef vector<path> vec;
vec v;
copy(directory_iterator(p), directory_iterator(), back_inserter(v));
sort(v.begin(), v.end());
for (vec::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it)
{
read(*it);
}
}
else
cout << p << " exists, but is neither a regular file nor a directory\n";
}
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
}
:
$ ./a.out ~/Desktop/test
"/home/usr/Desktop/test" is a directory containing:
"/home/usr/Desktop/test/a.out" size is 69446 perms 27746424350
"/home/usr/Desktop/test/la" is a directory containing:
"/home/usr/Desktop/test/la/Untitled Document" size is 0 perms 27746424170
"/home/usr/Desktop/test/la/lala" is a directory containing:
"/home/usr/Desktop/test/la/lala/Link to lalalala" is a link
"/home/usr/Desktop/test/la/lala/Untitled Folder" is a directory containing:
"/home/usr/Desktop/test/la/lala/lalalala" size is 0 perms 0
"/home/usr/Desktop/test/test.cpp" size is 2234 perms 0
"/home/usr/Desktop/test/test.cpp~" size is 2234 perms 0
. , 27746424350, , .