Good news for you is that if you don't give absolute paths to functions taking file address such as fopen
or mkdir
, they always assume the path is relative to the current address. Therefore, if you write:
mkdir("Outputs");
it will always make the Outputs
directory where you run the code. If you want to create the directory where the executable itself is (not where you run it from), you can see this question for how to retrieve the location of the running executable. In short, In linux, you can read what /proc/self/exe
points to. (You most likely want the first one though)
Regarding the permission, you can simply give it 0777 (octal for 111111111) which means all permission available. mkdir
(actually the system call under it) would automatically remove permissions you don't have from it (so you can't give the directory permissions you yourself don't have).
If you don't know what these bits represent, you can read on it in wikipedia. For the sake of completeness, I'll give a brief explanation. The permissions in traditional Unix systems (the ones returned when you do ls -l
) are in the form:
drwxrwxrwx
|\_/\_/\_/
| | | |
T O G R
T
tells what is the type of the file, for example d
for directory. O
is a set of three permissions for the owner of the file, G
is similar permissions but for the group the owner of the file belongs to and R
is permission for other (Sorry, the initial O
was already used ;). Each set of permissions (rwx
) choose read, write and execute permissions. You would need execute permission on a directory to be able to navigate to it.
So if you want to have some directory for yourself not hidden from others, you can give the permission as 0755. A private directory could have permission 0750 and a super private one could have permission 0700. A shared directory among all users could have permission 0777.