fileExistsAtPath:为存在的文件返回“否" [英] fileExistsAtPath: returning NO for files that exist

查看:186
本文介绍了fileExistsAtPath:为存在的文件返回“否"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码fileExistsAtPath中的某个点:对于已确认存在的文件,它返回NO.我一直在摸索,无法弄清为什么它不起作用,因此将其更改为以下代码,因为该目录绝对存在,但是无论如何都无法创建.

At a point in my code fileExistsAtPath: is returning NO for files that I have confirmed exist. I've been scratching my head at this and can't figure out why its not working, so changed it to this code as this directory absolutely exists but if it doesn't gets created anyway.

NSError* err = nil;
NSURL *dir = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
                                                       inDomain:NSUserDomainMask
                                              appropriateForURL:nil   
                                                         create: YES
                                                          error:&err];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[dir absoluteString]];

运行此代码后,应用程序目录文件夹存在,并且err为0,但不存在.

After running this code the application directory folder exists and err is 0, yet exists is NO.

怎么可能?

TIA

推荐答案

您应该使用[dir path],而不是[dir absoluteString].

这篇关于fileExistsAtPath:为存在的文件返回“否"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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