检查文件是否存在objective-c [英] check if a file exists objective-c

查看:235
本文介绍了检查文件是否存在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

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

路径


文件或目录的路径。如果路径以波浪号(〜)开头,则必须首先使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆