mkdir problems on create folders on MAC

Discussion in 'Mac Programming' started by ccjimmy, Apr 28, 2011.

  1. macrumors newbie

    Joined:
    Mar 15, 2011
    #1
    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?
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Mar 15, 2011
    #3



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

Share This Page