简体   繁体   English

NSFileManager fileExistsAtPath:&符号链接

[英]NSFileManager fileExistsAtPath: & symbolic links

In my ~/Library/Caches/ directory, I have a symbolic link to my app's bundle, and some symbolic links to images (eg "big_picture.png" is a symlink to "small_picture.png"). 在我的〜/ Library / Caches /目录中,我有一个指向我的应用程序包的符号链接,以及一些图像的符号链接(例如“big_picture.png”是“small_picture.png”的符号链接)。 When I try to check if the symlinks exist, using the NSFileManager's fileExistsAtPath: method, it returns NO , even when the symlink does exist, and it links to a file that exists as well. 当我尝试使用NSFileManager的fileExistsAtPath:方法检查符号链接是否存在时,即使符号链接确实存在,它也会返回NO ,并且它也链接到存在的文件。

As far as I know, Apple's documentation claims that what I'm trying to do should work. 据我所知,Apple的文档声称我正在尝试做的事情应该有效。 Am I doing something wrong, or is this a bug? 我做错了什么,或者这是一个错误?

fileExistsAtPath might follow the symlink. fileExistsAtPath可能遵循符号链接。 Maybe you can try a different method -- Use attributesOfItemAtPath:error: . 也许你可以尝试不同的方法 - 使用attributesOfItemAtPath:error: A dictionary will be returned if the file exists, and it will give you the ability to check the file type. 如果文件存在,将返回字典,并且它将使您能够检查文件类型。 To do the latter, call fileType on the dictionary and check it against NSFileTypeSymbolicLink . 要执行后者,请在字典上调用fileType并针对NSFileTypeSymbolicLink检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM