PDA

View Full Version : mkdir problems on create folders on MAC




ccjimmy
Apr 28, 2011, 04:07 AM
currently I use the function mkdir(const char* name,mode_t) to create a file-forder on MAC OS, it can create the folder in success. but When I double click the folder been created before to open it, MAC OS will prompt a messagebox which says I have no enough permission to see its content.
I've tried several times with the mode_t is 777,666,ect. the same result appears.

the path I want to create is /Users/$current_user/Document

any idea?



jiminaus
Apr 28, 2011, 04:21 AM
This code works for me:

#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>

int main (int argc, const char * argv[])
{
int r = mkdir("/Users/jim/NewFolder", 0777);
if (r == 0) {
printf("Success\n");
return EXIT_SUCCESS;
} else {
printf("Failed\n");
perror("Failed");
return EXIT_FAILURE;
}
}


I've just wondered if you've remembered to put the initial 0 in the mode so it's an octal constant and not an integer constant.

Assuming you're actually trying to create a Documents directory, why are you trying to do this? Every home directory (unless the user has gone to a lot of effort) will already have a Documents directory.

ccjimmy
Apr 28, 2011, 05:08 AM
This code works for me:

#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>

int main (int argc, const char * argv[])
{
int r = mkdir("/Users/jim/NewFolder", 0777);
if (r == 0) {
printf("Success\n");
return EXIT_SUCCESS;
} else {
printf("Failed\n");
perror("Failed");
return EXIT_FAILURE;
}
}


I've just wondered if you've remembered to put the initial 0 in the mode so it's an octal constant and not an integer constant.

Assuming you're actually trying to create a Documents directory, why are you trying to do this? Every home directory (unless the user has gone to a lot of effort) will already have a Documents directory.




thanks, I lost the initial 0 in the mode............
thank you,friend!