I am using the writeToFile:atomically:
method to write some encrypted data to a text file. The problem is, the file it needs to be saved as must be the file the user encrypts, with the extension I choose. Here is what I have so far:
[encryptedData writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]
stringByAppendingPathComponent:@"encryptedfile.txt.kry"] atomically:YES];
^//fileName here
As you can see, the encrypted filename is hardcoded as encryptedfile.txt.kry. But say the user selects the file "test.avi" to encrypt, the encrypted file that is written to the desktop should be named test.avi.kry. So there should be ofType:, like in NSBundle. I know there are some NSString methods here that I can use, but have forgotten.
Thanks!
Can't you just append the .kry onto the filename?
If you have the path, and just want the filename, you can use - (NSString *)lastPathComponent
:
NSString *filename = [filePath lastPathComponent];
[encryptedData writeToFile:[[NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"]
stringByAppendingPathComponent:[filename stringByAppendingString:@".kry"] atomically:YES];
If you want the filename without the extension you can use - (NSString *)stringByDeletingPathExtension
:
NSString *filename = [[filePath lastPathComponent] stringByDeletingPathExtension];