Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 28, 2011, 04:07 AM   #1
ccjimmy
macrumors newbie
 
Join Date: Mar 2011
mkdir problems on create folders on MAC

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?
ccjimmy is offline   0 Reply With Quote
Old Apr 28, 2011, 04:21 AM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: 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.
jiminaus is offline   0 Reply With Quote
Old Apr 28, 2011, 05:08 AM   #3
ccjimmy
Thread Starter
macrumors newbie
 
Join Date: Mar 2011
Quote:
Originally Posted by jiminaus View Post
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!
ccjimmy is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
create folders applescript joennie Mac Programming 3 Jul 30, 2013 06:43 PM
How to create more finder favorite folders? sambobsessed OS X 10.8 Mountain Lion 4 Apr 9, 2013 01:43 AM
Can't create new folders Killwin98 OS X 10.8 Mountain Lion 2 Feb 28, 2013 11:30 AM
Terminal Problems- I couldn't do the command mkdir ProgrammerNewb OS X 4 Jan 9, 2013 05:28 PM
Is there a way to create shortcuts for folders in the Save dialog? Doju Mac Basics and Help 2 Sep 17, 2012 02:50 PM

Forum Jump

All times are GMT -5. The time now is 06:31 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC