Load files for unknown sub-directory in custom folder

45 views Asked by At

I have a download manager which downloads files. Zip, deb etc.

When I go to my view controller containing those files is no problem. My goal is to navigate away if there is a folder in there.

So far I have created another table view controller which will be reused in case there are more folders.

However I'm stuck on how to show those files. It's not specific to a path as folders will vary.

Below is the relevant code used in the new view.

In viewDidLoad - Pulls files from loadDirectoryContents and file path:

directoryContents = [[NSMutableArray alloc]init];
[self loadDirectoryContents:(NSString*)[self filePath]];

This is where is finds the files and sends to the viewDidLoad:

-(NSString*)filePath 
{       
    self.directoryPath = [[@"~/Documents/my folder" stringByExpandingTildeInPath] retain];

    NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    documentsPath = [directoryContents objectAtIndex:0];

    NSLog(@"%@",directoryPath);
    return directoryPath;
}

-(void)loadDirectoryContents:(NSString*)a 
{
    NSError *error=nil;
    NSArray *pathArray=[[NSFileManager defaultManager]subpathsOfDirectoryAtPath:directoryPath error:&error];

    if (error) 
    {
        NSLog(@"ERROR: %@",error);
    }
    else
    {
        if (pathArray) 
        {
            [directoryContents removeAllObjects];
            [directoryContents addObjectsFromArray:pathArray];
        }
    }
}

I think the loadDirectoryContents is correct as it's looking for the sub path.

It's the filePath that's not working. As there is no specific file path.

How would I fix this so it will load whatever is in that folder? If I need to update this post with more code, let me know.

Any help would be appreciated.

Thank You.

0

There are 0 answers