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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:37:19+00:00 2026-06-10T08:37:19+00:00

Here is my code. NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *toPath = [[pathSong

  • 0

Here is my code.

NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"Songs"];
    NSString *fromPath=[[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"abc"];
    NSString *strdestination = [fromPath stringByAppendingPathComponent:@"sg.mp3"];
    NSError *Error;
    if([[NSFileManager defaultManager]fileExistsAtPath:strdestination]){
        if([[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error]==NO){
            UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [Alert show];
        }
        else{
            UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"Not copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [Alert show];
        }
    }

I am getting the error logo :

Error Domain=NSCocoaErrorDominCode=516 “The operation couldn’t be
completed .(Cocoa arrow 516.)” userInfo=0x681abf0

NSUnderlyingError =0x681b920 “The operation couldn’t be completed
.File exists”

abc folder there is no song name “sg.mp3” but I’m still getting the file exists error. I don’t know where I did mistake?

  • 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-10T08:37:20+00:00Added an answer on June 10, 2026 at 8:37 am

    There is two issues in your code:

    1. You need to remove the file if it is already there
    2. You need to specify a name for the destination file, means if you use like:

    NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"Songs"];

    and

    [[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error];
    

    Then if copy occurs, it will copy the Sg.mp3 file as Songs without any type.

    So you need to write it like:

    NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *tempPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"Songs"];
    NSString *toPath = [tempPath stringByAppendingPathComponent:@"yourFileName.mp3"];
    NSString *fromPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"abc"];
    NSString *strdestination = [fromPath stringByAppendingPathComponent:@"sg.mp3"];
    NSError *Error = nil;
    
    if([[NSFileManager defaultManager]fileExistsAtPath:strdestination])
    {
    
      if([[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error]==NO)
       {
           UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
           [Alert show];
       }
       else
       {
          [fileManager removeItemAtPath:strdestination error:NULL];
           UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"Not copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
           [Alert show];
       }
    }
    

    This code will remove the file if exist at destination and then copy the sg.mp3 from abc folder to Songs folder with the name yourFileName.mp3

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

Sidebar

Related Questions

Here is my code:- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths
I've got pretty simple code out here: NSArray* divisions = [[NSString stringWithFormat: @%d, system(ssh
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
Here is my piece of code that creates buttons programmatically: NSArray *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@Cover_0.png],
Here is the code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier
Here's my code: -(void)randommoves { NSArray *possiblemoves =[NSArray arrayWithObjects:@R ,@R' ,@L ,@L' ,@B ,@B'
Possible Duplicate: How do I iterate over an NSArray? Here is my code (for
here is the code I am referring to: NSArray *views = [[NSArray alloc] initWithObjects:addPVC,
A couple of questions regarding the following code: @implementation NSArray (Find) - (NSArray *)findAllWhereKeyPath:(NSString
The script is on jsfiddle here : CODE What it does at the moment

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.