2

I have a code to get objects out of the path @"/Users/playra/Desktop/2 DivyaLoka/Собрание Тайн"

- (void) setPathProperty:(NSString *)pathProperty
{
    _pathProperty = pathProperty;
    NSArray* allContents = [[NSFileManager defaultManager]  contentsOfDirectoryAtPath:pathProperty error:nil];
    self.contents = allContents;
    [self.tableView reloadData];
    self.navigationItem.title = [self.pathProperty lastPathComponent];
}

Below in this line comes object .DS_Store

NSArray* allContents = [[NSFileManager defaultManager]  contentsOfDirectoryAtPath:pathProperty error:nil];

How to remove it from there?

setoffonom
  • 21
  • 2

1 Answers1

1

Try this :

NSMutableArray * dirContents = [[NSMutableArray alloc] initWithArray:docDir];
if([docDir containsObject:@".DS_Store"])
{
    [dirContents removeObject:@".DS_Store"];
}
Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
  • Are you sure that `removeObject:` will remove matching strings or only the specific object instance (i.e. the string constant `@".DS_Store"`)? – trojanfoe Apr 01 '14 at 07:02
  • yeah it'll remove from array – Mayur Prajapati Apr 01 '14 at 07:02
  • 2
    +1 but note that the check for `containsObject` isn't needed. – user3386109 Apr 01 '14 at 07:04
  • 1
    @Mayur It helped me. http://stackoverflow.com/questions/5851164/ignore-ds-store-and-icon-files-in-a-folder-with-cocoa-nsfilemanager NSMutableArray *fullPaths = [NSMutableArray array]; NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; NSArray *subpaths = [fileManager subpathsAtPath:filePath]; for (NSString *subpath in subpaths) { if ( ![[subpath lastPathComponent] hasPrefix:@"."] && ![[subpath lastPathComponent] isEqualToString:@"Icon\r"]) { [fullPaths addObject:[filePath stringByAppendingPathComponent:subpath]]; } } // continue – setoffonom Apr 01 '14 at 11:24
  • @setoffonom ok great enjoy :) – Mayur Prajapati Apr 01 '14 at 11:26