How to check if a file exists in Documents folder?

后端 未结 7 1377
小蘑菇
小蘑菇 2020-11-29 14:53

I have an application with In-App Purchase, that when the user buy something, download one html file into the Documents folder of my app.

Now I must check if this HT

7条回答
  •  执笔经年
    2020-11-29 15:33

    If you set up your file system differently or looking for a different way of setting up a file system and then checking if a file exists in the documents folder heres an another example. also show dynamic checking

    for (int i = 0; i < numberHere; ++i){
        NSFileManager* fileMgr = [NSFileManager defaultManager];
        NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSString* imageName = [NSString stringWithFormat:@"image-%@.png", i];
        NSString* currentFile = [documentsDirectory stringByAppendingPathComponent:imageName];
        BOOL fileExists = [fileMgr fileExistsAtPath:currentFile];
        if (fileExists == NO){
            cout << "DOESNT Exist!" << endl;
        } else {
            cout << "DOES Exist!" << endl;
        }
    }
    

提交回复
热议问题