when I execute this code, I get the error Couldn't create backup sub-directory: Permission denied
but I can't understand why since I give full permisions and I'm using a admin account on ubuntu.
umask(0777);
int folder_date_status = mkdir(filepath_W, 0777);
if(folder_date_status == -1){
perror("Couldn't create backup sub-directory");
return -1;
}
An admin account doesn't run with full privileges by default. This is so that programs you run don't unexpectedly act as privileged users (ie. you must explicitly give permission).
To give permission to the program to create a sub-directory in a directory which requires privileged access, try using sudo
.
If the program name is called myprogram
, try running:
sudo ./myprogram
Then type your password if it is requested.
Note that super-user access should only be required if it is trying to make a subdirectory in a write-restricted directory (eg. restricted directory owned by root, or another user). Also ensure that the parent directory exists (otherwise it could also throw an error).