Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ccjimmy

macrumors newbie
Original poster
Mar 15, 2011
14
0
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

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
This code works for me:
Code:
#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

macrumors newbie
Original poster
Mar 15, 2011
14
0
This code works for me:
Code:
#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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.