I'm looking to return an NSArray
which contains all of the files URLS
located within a particular folder in iOS
.
In this case I'm looking inside the Ryan/Bob/FolderWithInfo - which contains 4 files. I want to get the file URL
of each of these files.
Here is a example of an output I'm looking for :
NSArray *array = @[
@"file:///var/mobile/Applications/8D5EBBB2-6726-4FE9-95CB-453635443643/Documents/Ryan/Bob/FolderWithInfo/Layout1.csv",
@"file:///var/mobile/Applications/8D5EBBB2-6726-4FE9-95CB-453635443643/Documents/Ryan/Bob/FolderWithInfo/Layout2.csv",
@"file:///var/mobile/Applications/8D5EBBB2-6726-4FE9-95CB-453635443643/Documents/Ryan/Bob/FolderWithInfo/Layout3.csv",
@"file:///var/mobile/Applications/8D5EBBB2-6726-4FE9-95CB-453635443643/Documents/Ryan/Bob/FolderWithInfo/Layout4.csv",
];
How is this achievable?
Edit: I have tried this and thought of maybe prepending the main path after, but there has to be a more efficient way :)
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
directory = [NSString stringWithFormat:@"%@/%@/%@/%@", directory, @"Ryan, @"Bob", @"FolderWithInfo"];
NSArray *files=[fileMgr contentsOfDirectoryAtPath:directory error:&error];
NSLog(@"mag1 directory: %@",files);
Thanks.