Search code examples
objective-ciosmacosnsfilemanager

NSFileManager moveItemAtPath:toPath:error: changes filename


I have a importFile stored at NSString* importFile (printed with NSLog %@):

/var/mobile/Applications/5CE1D252-E56A-4AAC-B88E-5B0CEFFF55B3/Library/Caches/tmp/temp_695D39E3-3359-415F-9C0D-243E2E117B8B-456-0000001384C17BBA.tmpfile

I then receive a destinationFile NSString * destinationFile a value of (printed with NSLog %@)

/var/mobile/Applications/5CE1D252-E56A-4AAC-B88E-5B0CEFFF55B3/Documents/Str%208829%20-%20Test.500887280

then I use NSFileManager to move the file:

NSFileManager* fileManager = [NSFileManager defaultManager];
assert(fileManager != nil);
NSError* error = nil;
[fileManager moveItemAtPath:importFile toPath:destinationFile error:&error];

the problem is that the actual file's name after the move is different from the requested destinationFile:

Str%25208829%2520-%2520Test.500887280

what's going on here ? what are those extra three 25 that seem to be the difference ?


Solution

  • It looks like the % in the filename is being encoded as %25 (the percent code for percent)

    You might check this one out: URL-encoding and HTML-encoding NSStrings