检查文件是否存在于iPhone目录中的文件夹中 [英] Check file exists in a folder inside Directory in iPhone

查看:122
本文介绍了检查文件是否存在于iPhone目录中的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone新手,

I am new to iPhone,

我要检查DocumentDirectory内的文件夹中是否存在Myfile?

I want to check whether Myfile exists in folder inside DocumentDirectory ?

例如:

Myfile.epub是我的文件之一,我想检查此文件是否存在于我的DestPath吗?

Myfile.epub is one of my file and i want to check whether this file exists at my DestPath or not ?

DestPath是我的DocumentDirectory路径.

DestPath=/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/D414BC19-C005-4D93-896D-A6FB71DE4D21/Documents/Derivatives

任何帮助将不胜感激.

推荐答案

此解决方案对我有用..
您不想给出整个路径,例如/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/D414BC19-C005-4D93-896D-A6FB71DE4D21/Documents/Derivatives >

This solution worked for me..
You don't want to give the entire part of your path like /Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/D414BC19-C005-4D93-896D-A6FB71DE4D21/Documents/Derivatives

您必须提供 Derivatives/Myfile.epub(文件夹名称/文件名)以检查文件路径

you have to give Derivatives/Myfile.epub (FolderName/filename) for checking the file path

    NSFileManager *filemanager=[NSFileManager defaultManager];  

    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory= [paths objectAtIndex:0];

    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Derivatives/Myfile.epub"];

    BOOL success =[filemanager fileExistsAtPath:path];

    if (success == YES) {   

        NSLog(@"exists");
    }
    else {

       NSLog(@"not exists");

    }

这篇关于检查文件是否存在于iPhone目录中的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆