I'm trying to remove specific files from a directory using NSFileManager. I would like to ignore the hidden .DS_Store and Icon files (the folder that I'm checking has to have a custom icon) that are in the directory, however I keep accidentally deleting them as well. Right now, I'm doing the following:
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *dirContents = [manager contentsOfDirectoryAtPath:[selectedFolder stringValue] error:nil];
for (int i = 0; i < [dirContents count]; i++)
{
NSString *theFile = [dirContents objectAtIndex:i];
if([theFile isEqualToString:@".DS_Store"] || [theFile isEqualToString:@"Icon?"] || [theFile isEqualToString:@"Icon"])
{
continue;
}
//do manipulations on files here
}
[manager release];
However, the .DS_Store and Icon files aren't being matched in my if statement. Additionally, when I show hidden files in Finder, the icon file is called "Icon". However, doing an ls in that directory in terminal prints out "Icon?".
How can properly I parse these files out in my code?
Thanks
EDIT: So it actually is successfully ignoring the .DS_Store file, but the Icon file is still getting past the if statement.