Jorge
Jorge

Reputation: 1532

Access file directory outside main Bundle

I have a NSArray of strings, something like this:

OBJECT 1 OBJECT 2 OBJECT 3

Now, Inside a local folder, I have folders with the objects name:

/User/Dropbox/ALLOBJECTS

OBJECT 1 OBJECT 2 OBJECT 3

Inside each folder, I have two pictures named after the objects:

OBJECT1-PIC1.png OBJECT1-PIC2.png

What I need is the path to those pictures, basically, My object has two columns (FILE1, FILE2) which I want to save the pictures.

I will iterate through the array, find the Folder with the same name (inside a local folder) and copy the pictures.

I'm trying to use, as a test:

NSString *filePath = @"~/Users/me/Dropbox/ALLOBJECTS"

NSData *data = [[NSFileManager defaultManager] contentsAtPath:filePath];

NSLog(@"data: %@", data);

but am getting NULL data.

Is it possible to achieve this?

Upvotes: 0

Views: 450

Answers (1)

dKrawczyk
dKrawczyk

Reputation: 329

This will only work on the simulator.

NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray* rootContent = [fileManager contentsOfDirectoryAtPath:@"/Users/me/Pictures" error:nil];
NSLog (@"pictures dir contains:");
for (NSString* fileName in rootContent)
    NSLog (@"%@", fileName);

NSData *data = [fileManager contentsAtPath:@"/Users/me/Pictures/Pw0wF.png"];

UIImage *image = [UIImage imageWithData:data];

Upvotes: 1

Related Questions