问题描述
我是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目录中的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!