检查文件是否存在objective-c [英] check if a file exists objective-c
问题描述
我使用下面的代码检查文件是否存在
I used the codes below to check if a file exists
bool b=[[NSFileManager defaultManager] fileExistsAtPath:filePath];
代码适用于IOS。
但是当我将它迁移到mac os x,
But When I migrate it to mac os x,
但是我发现文件是否存在于磁盘上与filePath,
b总是返回0,这意味着文件不存在。
But I found whether the file exists on disk with filePath, b always returns 0, which means the file does not exists.
我想知道ios和macosx之间是否有区别
I wonder if there is difference between ios and macosx
欢迎任何评论
推荐答案
从文档,我认为你使用 tilde
From docs, I think you're using path with tilde
路径
文件或目录的路径。如果路径以波浪号(〜)开头,则必须首先使用stringByExpandingTildeInPath进行扩展,否则此方法将返回NO。
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
创建相对于您的主目录的路径(例如 / Users / username /
)
tilde
makes path relative to your home directory (such as /Users/username/
)
你可以通过调用 NSLog(@%@,filePath);
如果filePath类型为NSString
you can find out by calling NSLog(@"%@",filePath);
if filePath is of type NSString
这篇关于检查文件是否存在objective-c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!