Getting a list of files in the Resources folder - iOS

前端 未结 7 2246
悲哀的现实
悲哀的现实 2020-11-28 19:52

Let\'s say I have a folder in my \"Resources\" folder of my iPhone application called \"Documents\".

Is there a way that I can get an array or some type of list of a

7条回答
  •  心在旅途
    2020-11-28 20:26

    You can get the path to the Resources directory like this,

    NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
    

    Then append the Documents to the path,

    NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Documents"];
    

    Then you can use any of the directory listing APIs of NSFileManager.

    NSError * error;
    NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
    

    Note : When adding source folder into the bundle make sure you select "Create folder references for any added folders option when copying"

提交回复
热议问题