Testing file existence using NSURL

前端 未结 6 2063
失恋的感觉
失恋的感觉 2020-12-07 20:10

Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services\' FSRefs.

However, there\'s one task I can\'t find a

6条回答
  •  自闭症患者
    2020-12-07 20:32

    Because NSURL can represents more that local file-systems, I don't think that there is a generic method that can test for their existence in a reliable way. At least, the Cocoa foundation does not contains such a function (as far as I know).

    If you only deal with local file-systems, I suggest you to create a category for NSURL or for NSFileManager, with a urlExists: message. It would convert the NSURL to a NSString (normalized path) and then invoke the [NSFileManager fileExistsAtPath:] message.

提交回复
热议问题