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 4324332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:07:06+00:00 2026-05-21T09:07:06+00:00

In my application, I let the user record a sound clip and later, if

  • 0

In my application, I let the user record a sound clip and later, if the user chooses, I want him to be able to delete it.

This is the code I use:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSLog(@"File exists: %d", [fileManager fileExistsAtPath:path]);
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:path]);
[fileManager removeItemAtPath:path error:&error];
if (error != nil)
{
    NSLog(@"Error: %@", error);
    NSLog(@"Path to file: %@", path);
}

The problem is that fileExistsAtPath and isDeletableFileAtPath return null and the removeItemAtPath doesn’t work, and throws this error,

Error: Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x391b7f0 “Operation could not be completed. (Cocoa error 4.)”

The path has this form:

/Users/andrei/Library/Application%20Support/iPhone%20Simulator/User/Applications/5472B318-FA57-4F8D-AD91-7E06E9609215/Documents/1280913694.caf

There is a file there called 1280913694.caf, but it doesn’t pick it up. Does it have something to do with the way in which the path should be represented?

The path works when playing the audio file with AVAudioPlayer.

I’ve also changed the %@ to %d for fileExistsAtPath and isDeletableFileAtPath and the answer is 0, which I suppose means FALSE.

The name of the file is stored in a database, and the path to the file is retrieved with this method:

-(NSString *)returnFullPathToDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return documentsDirectory;
}

After I get this value, I use it in the following code

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
  • 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-05-21T09:07:06+00:00Added an answer on May 21, 2026 at 9:07 am

    Your check for (error != nil) is incorrect. You should set a BOOL to the return value of the method and use that to handle error conditions as it is possible for the method to complete successfully and for error to be non nil afterwards. So, the file might actually have been deleted but you are getting an incorrect error back.

    You should also not try to delete the file if it doesn’t exist.

    Also, I usually just log the error’s localizedDescription as that is easier to read

    This code works in my project (path was defined elsewhere):

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        BOOL fileExists = [fileManager fileExistsAtPath:path];
        NSLog(@"Path to file: %@", path);        
        NSLog(@"File exists: %d", fileExists);
        NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:path]);
        if (fileExists) 
        {
            BOOL success = [fileManager removeItemAtPath:path error:&error];
            if (!success) NSLog(@"Error: %@", [error localizedDescription]);
        }
    

    related answer:
    NSError: Does using nil to detect Error actually turn off error reporting?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If we want in our WPF application to let a user make a SQL
I want to add a feature to our application that let's a user know
I want to let application user know that whom buddy has downloaded the application
I have a simple application in which I need to let the user select
I'm developing a C# web application in VS 2008. I let the user select
I want my application to reset shared preferences when the application reinstalling let's say
Let's say that I have an application frame, and I want to show a
I have a windows form application which let an user to write in a
I need to use Facebook's Request Dialog to let user invite their friends. I
In my application,I do not want two user login with the same login name.

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.