代码之家  ›  专栏  ›  技术社区  ›  Banjer

如何将nshomedirectory文件列表转储到nslog

  •  1
  • Banjer  · 技术社区  · 14 年前

    在nshomedirectory中,是否有一种快速的方法可以为特定文件夹列出目录列表?我在玩一个例子 ASIHTTPRequest 通过以下方式下载图像:

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

    我想列出documents文件夹中的文件,以查看为了调试而实际下载的内容。谢谢你的帮助。

    1 回复  |  直到 14 年前
        1
  •  3
  •   Banjer    14 年前

    找到了我问题的答案,谢谢 this page . 这将为您提供一个不错的文件列表:

    // 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]);
    
    推荐文章