Search code examples
iphonenslog

How to dump NSHomeDirectory file listing to NSLog


Is there a quick way to spit out a directory listing for a specific folder in NSHomeDirectory? I'm playing with an example in ASIHTTPRequest that downloads an image via:

[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"totallyhotmilf.jpg"]];

I'd like to list the files in the Documents folder to see whats actually getting downloaded for debugging purposes. Thanks for the help.


Solution

  • Found an answer to my question thanks to this page. This will give you a nice file listing:

    // Create file manager
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    
    // Point to Document directory
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    
    // Write out the contents of home directory to console
    NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);