Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:00:39+00:00 2026-06-01T21:00:39+00:00

I’m having some problems trying to create a folder using NSFileManager in MacOS X.

  • 0

I’m having some problems trying to create a folder using NSFileManager in MacOS X. I’m creating the software in Lion if that changes anything.

Anyway. The program structure is something like this:

  1. Fill in some fields.
  2. Choose a folder using NSOpenPanel.
  3. The program generates the name of the new folder from the fields.
  4. Create a folder with that name in the chosen folder.

The code that is supposed to create the folder looks like this:

NSString *name = [pnameField stringValue];
NSString *number = [self parseVerknr:[pnumberField stringValue]];
NSString *date = [pdateField stringValue];
NSString *folderName;

//Here I generate the folder name from some rules and stuffsies
//It ends up as something like: 13245_08 - cp. - name

NSOpenPanel *myPanel = [NSOpenPanel openPanel];

    myPanel.canChooseFiles = NO;
    myPanel.canChooseDirectories = YES;
    myPanel.canCreateDirectories = YES;

    [myPanel beginWithCompletionHandler:^(NSInteger result){

        if (result==NSFileHandlingPanelOKButton){

            NSFileManager *myManager = [[NSFileManager alloc] init];

            NSError *merror;

            NSString *directoryString = [NSString stringWithFormat:@"%@%@", [myPanel.URL absoluteString], folderName];

            //Here the directory string looks like file://localhost/Users/username/Documents/folders/12345_09 - cp. - Koop
            directoryString = [directoryString substringFromIndex:6];
            //After it looks like: /localhost/Users/username/Documents/folders/12345_09 - cp. - Koop
            NSLog(@"directory: %@", directoryString);

            [myManager createDirectoryAtPath:directoryString withIntermediateDirectories:YES attributes:nil error:&merror];

            NSLog(@"%@", [merror localizedDescription] );
        }

    }];

If I don’t take the substring from index 6 I get a large error stack (tried to take it from 16 too which did the same). If I use the split string I get the following error:

You don’t have permission to save the file “localhost” in the folder “PK Bear”.

Since PK Bear is the name of my “hard drive” I’m guessing the program needs to get permission to access the hard drive. I just have no idea how to do this.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:00:42+00:00Added an answer on June 1, 2026 at 9:00 pm

    The problem is the way you’re creating the path string. In particular, -[NSURL absoluteString] returns a string representation of the URL, not a filepath string. You should use NSURL and NSString’s methods for working with paths. As explained in the documentation, -[NSURL path] returns a path string suitable for inputting into NSFileManager methods.

    Try this:

    NSString *directoryString = [[myPanel.URL path] stringByAppendingPathComponent:folderName];
    [myManager createDirectoryAtPath:directoryString withIntermediateDirectories:YES attributes:nil error:&merror];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.