I am using this code to make an array with all the documents in the Documents folder of my app… Here is the code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);'
How do I exclude .DS_Store from the array?
You can’t exclude the
.DS_Storefiles with that method, unless you want to do a second step, and filter them out of your filePathsArray. If you want to do it one step, then usecontentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:. You can pass nil for the properties andNSDirectoryEnumerationSkipsHiddenFilesfor the options. You would also have to change the way you get path, and useURLsForDirectory:inDomains:to get the URL of the documents directory.