I create one folder in the document directory named newFolder. Now I want to know how to create a txt file in my folder, which is created using newFolder. Now I can create a file in the document directory, but how to create a file in mine which is created by me. I want to get this file also from newFolder and go to the mail composer in iPhone.
This is the create folder in the folder of my document, but now I want to create a file in this newFolder folder name to help me with this.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"newFolder"];
NSError *error = NULL;
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
I am writing this code, but my csv file is being created in the douter diretory folder. I want to create this file in my folder that has a doument directory named newFolder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
NSString *filename = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"EmployeeBase.Csv"]];
NSError *error = NULL;
BOOL written = [csvString writeToFile:filename atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!written)
NSLog(@"write failed, error=%@", error);
source
share