Reputation: 21805
NSURL* suppurl = [manager URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSString *path = [suppurl path];
NSLog(@" Path %@",path);
NSString* myfolder = [path stringByAppendingPathComponent:@"MyFolder"];
NSDirectoryEnumerator* myFolderDir = [manager enumeratorAtPath:myfolder];
for (NSString* file in myFolderDir)
{
NSLog(@" file %@",file);
NSString *getImagePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",file]];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:getImagePath];
NSLog(@" image path %@",getImagePath);
if (exists)
{
NSLog(@" exists");
}
The first NSLog(@" file %@",file);
successfully logs the file name... but the BOOL exists doesn't .
What could be the problem?
Upvotes: 0
Views: 79
Reputation: 8520
You are enumerating files in myFolderDir
, but then you are trying to verify if an equally-named file exists in path
. Replace with:
NSString *getImagePath = [myFolderDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",file]];
Also, note that you don't need to do this:
[NSString stringWithFormat:@"%@",file]
.. file
already being an NSString
.
In case you're trying to enumerate images in that folder, consider testing the file extension:
if ([[file pathExtension] isEqualToString: @"jpg"]) {
// load the image
[self loadImage: [myFolderDir stringByAppendingPathComponent:file]];
}
Upvotes: 1