Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Correct me if I am wrong. You want to get the number of mp3 in your folder, but while a folder only contains folders and mp3 files, the mp3-count is for its parent folder (and if the parent itself only contains folders and mp3s, it counts for its grand-parent, etc.) right ?</p> <p>[manager enumeratorAtPath] is quite useful, but in this case it will certainly require you to maintain a stack to keep track of your browsed files.</p> <p>Recursion is bliss, here.</p> <pre><code>- (BOOL)isMp3File:(NSString*)file { return [file hasSuffix:@".mp3"]; } - (BOOL)isHiddenFile:(NSString*)file { return [file hasPrefix:@"."]; } - (void)parseForMp3:(NSMutableDictionary*)dic inPath:(NSString*)currentPath forFolder:(NSString*)folder { BOOL comboBreak = false; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError* error; NSArray* files = [fileManager contentsOfDirectoryAtPath:currentPath error:&amp;error]; if (error) { //throw error or anything } for (NSString *file in files) { BOOL isDirectory = false; NSString *fullPath = [NSString stringWithFormat:@"%@/%@", currentPath, file]; [fileManager fileExistsAtPath:fullPath isDirectory:&amp;isDirectory]; comboBreak = comboBreak || (!isDirectory &amp;&amp; ![self isMp3File:file] &amp;&amp; ![self isHiddenFile:file]); if (comboBreak) break; } for (NSString *file in files) { BOOL isDirectory = false; NSString *fullPath = [NSString stringWithFormat:@"%@/%@", currentPath, file]; [fileManager fileExistsAtPath:fullPath isDirectory:&amp;isDirectory]; if (isDirectory) { if (!comboBreak) { [self parseForMp3:dic inPath:fullPath forFolder:folder]; } else { [self parseForMp3:dic inPath:fullPath forFolder:fullPath]; } } else if ([self isMp3File:file]) { NSNumber *oldValue = [dic valueForKey:folder]; oldValue = [NSNumber numberWithUnsignedInteger:[oldValue unsignedIntegerValue] + 1]; [dic setValue:oldValue forKey:folder]; } } } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [self parseForMp3:dic inPath:@"/Users/panosbaroudjian" forFolder:@"/Users/panosbaroudjian"]; NSLog(@"%@", dic); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload