Note that there are some explanatory texts on larger screens.

plurals
  1. PORenaming and moving file using NSFIleManager
    primarykey
    data
    text
    <p>This is my code to rename and move file from a temporary directory to My Documents directory.</p> <p>So the problem is within two sections of mode Create a Directory and Attempt to move. The rest all is working correctly..</p> <p>When I comment out the Create directory section, the Attempt to Move section logs in the console:</p> <blockquote> <p>Unable to Move the File..Error Code 4.</p> </blockquote> <p>Now I researched error code 4 and it means that the directory does not exist. So I added the code to create the directory.</p> <p>Now when I run the program the directory is created but the Attempt to Move section logs:</p> <blockquote> <p>Unable to Move File..error code 512</p> </blockquote> <p>Now researching on it it is due to the file already exists. The destination must not exist.</p> <p>So I am pretty confused, since both error codes are contracting each other. </p> <pre><code>{ NSError *error; NSFileManager* manager = [[NSFileManager alloc] init]; NSString* tempFile =[NSTemporaryDirectory() stringByAppendingPathComponent:@"recordTest.caf"]; if (tempFile) { // Get the Documents Directory NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSLog(@"Documents directory: %@", [manager contentsOfDirectoryAtPath:documentsDirectory error:&amp;error]); //Get the User File Save Name from the text field NSString *UserText = [[self FileNameText] text]; // Rename the file, by moving the file NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:UserText]]; // Create a Directory if( [manager createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",documentsDirectory,UserText] withIntermediateDirectories:NO attributes:nil error:&amp;error]!= YES) { NSLog(@"Directory error"); } if([manager fileExistsAtPath:[NSString stringWithFormat:@"%@/%@",documentsDirectory,UserText]]) { NSLog(@"Path exist"); NSLog(@"Documents directory: %@", [manager contentsOfDirectoryAtPath:documentsDirectory error:&amp;error]); } // Attempt the move if ([manager moveItemAtPath:tempFile toPath:filePath2 error:&amp;error] != YES) { NSLog(@"Unable to move file: %@", [error localizedDescription]); } else { if ([manager removeItemAtPath:tempFile error:&amp;error] != YES) NSLog(@"Unable to delete file: %@", [error localizedDescription]); } } [manager release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload