简体   繁体   中英

retrieving documents from applications directory

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?

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]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM