0

我是 iPhone 新手,

我想检查Myfile里面的文件夹是否存在DocumentDirectory

例如:

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

DestPath是我的DocumentDirectory道路。

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

任何帮助将不胜感激。

4

3 回答 3

3

该解决方案对我有用..
您不想提供路径的整个部分,例如/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/D414BC19-C005-4D93-896D-A6FB71DE4D21/Documents/衍生品

您必须提供Derivatives/Myfile.epub (FolderName/filename) 以检查文件路径

    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");

    }
于 2012-08-01T07:22:23.823 回答
2

你也可以试试。。

NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"file"];
success=[filemanager fileExistsAtPath:path];
于 2012-08-01T07:29:40.993 回答
0
 //Get the Document directory path 

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
 NSString *documentsPath = [paths objectAtIndex:0]; 
 documentsPath = [documentsPath stringByAppendingPathComponent:@"Myfile.epub"];
 if (![[NSFileManager defaultManager] fileExistsAtPath:documentsPath]) 
 {
    //file not exits in Document Directories
 }
  else
  {
    //file exist in Document Directories
  }
于 2012-08-01T10:53:59.343 回答