计算目录和子目录中的文件?苹果手机

Wri*_*sCS 1 iphone file count nsfilemanager subdirectory

我试图计算目录中的整个文件,包括子目录.这是我必须计算第一个文件夹中的文件:

-(NSString *)numberOfPhotos
{
    NSString *MyPath = @"/rootdirectory/"; 
    NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:MyPath]; 

    return [NSString stringWithFormat:@"%d", [directoryContent count]];
}
Run Code Online (Sandbox Code Playgroud)

我想的可能是类似的东西

for (file in folder){
    [file count]
{
Run Code Online (Sandbox Code Playgroud)

但似乎没有用.

更新: 实际上,非常简单:

NSDirectoryEnumerator *subs = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:musicPath error:nil];
Run Code Online (Sandbox Code Playgroud)

Wri*_*sCS 5

NSDirectoryEnumerator *subs = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:musicPath error:nil];
Run Code Online (Sandbox Code Playgroud)