check if a file exists objective-c

后端 未结 1 1226
栀梦
栀梦 2021-02-20 01:55

I used the codes below to check if a file exists

bool b=[[NSFileManager defaultManager] fileExistsAtPath:filePath];

The codes worked on IOS.

相关标签:
1条回答
  • 2021-02-20 02:45

    From docs, I think you're using path with tilde

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/fileExistsAtPath:isDirectory:

    path

    The path of a file or directory. If path begins with a tilde (~), it must first be expanded with stringByExpandingTildeInPath, or this method will return NO.

    tilde makes path relative to your home directory (such as /Users/username/)

    you can find out by calling NSLog(@"%@",filePath); if filePath is of type NSString

    0 讨论(0)
提交回复
热议问题