Is it possible to save a file (any type) inside a custom folder in NSDocumentDirectory
? I mean every time whatever I try to save I use this as resource file path:
NSArray *pathComponents = [NSArray arrayWithObjects:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], fileName, nil];
outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
or
NSString *imageDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
And as a result it always save in the following directory,
~/Library/Application Support/iPhone Simulator/......./Documents/file.ext
But is it possible to save that file inside a custom folder like this:
~/Library/Application Support/iPhone Simulator/......./Documents/CustomFolder/file.ext
.
If yes, Could you tell me details about the process?
Thanks in advance.
Have a good day.
Additional:
Here, Actually I save an audio voice record file. The name of that file came from current time. I want to save that voice record file in a custom folder.
Here is my code:
- (NSString *) dateString
{
// return a formatted string for a file name
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"ddMMMYYY_hh:mm:ssa";
return [[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".m4a"];
}
// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], fileName, nil];
outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
In outputFileURL
I save my recorded voice.
I try with this :
// Set the audio file
NSString *customDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
customDirectoryPath = [customDirectoryPath stringByAppendingPathComponent:@"MyCustomDirectory"];
NSArray *pathComponents = [NSArray arrayWithObjects:customDirectoryPath, fileName, nil];
NSLog(@"pathComponents %@", pathComponents);
outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"outputFileURL %@", outputFileURL);
The folder is created with out any problem but the audio file is not save in that folder. Thanks.
Yes it is possible. You just need to create a folder inside document directory.
Then fetch the folder everytime you want to store something and store into it.