Way to create and set permissions for folders

Hey guys. I am running a program in Ubuntu and on start up I need to make sure certain files/folders exist before continuing.

Currently I am using the following to make sure folders exist...
 
system("mkdir /directory");

...and then using the following to ensure the permissions are set correctly...
 
system("chmod 777 /directory");

...however I feel that this is not a particularly good implementation, and is certainly not cross platform.

Does anyone know of a simple, lightweight way to 1) check if a specified folder exists, 2) create folders, and 3) set folder permissions.

A cross platform method would be nice but is not vital :)

Thanks in advance guys.
Use stat() [man 2 stat], then check the st_mode field. There is a macro S_ISDIR() which takes the st_mode field and
returns true if the stat'ed thing is a directory.

Use mkdir() [man 2 mkdir]. One of its parameters is the permissions to use.

(At least, these are both POSIX compliant. If you want true platform independence, you'll need to use a library
such as boost::filesystem).

the UNIX concept of permissions are not cross platform anyway.
anyhow those 2 command will work on any unix I know.

but jsmith is right, use stat and there is a chmod in sys/stat.h

you should download the programming man pages.
unfort ubuntu sucks for development out of the box.
no man pages no development libs.

all the C/unix system libraries have man pages, easy.
Topic archived. No new replies allowed.