美文网首页
[[NSFileManager defaultManager]

[[NSFileManager defaultManager]

作者: 摩卡奇 | 来源:发表于2017-11-21 11:30 被阅读93次

https://stackoverflow.com/questions/34135305/nsfilemanager-defaultmanager-fileexistsatpath-returns-false-instead-of-true

Apparently your path variable is a NSURL (describing a file path). To get the path as a string, use the path property, not absoluteString:

if let filePath = path.path {
    let exists = NSFileManager.defaultManager().fileExists(atPath: filePath)
}

absoluteString returns the URL in a string format, including the file: scheme etc.

Example:

let url = NSURL(fileURLWithPath: "/path/to/foo.txt")

// This is what you did:
print(url.absoluteString)
// Output:    file:///path/to/foo.txt

// This is what you want:
print(url.path!)
// Output:    /path/to/foo.txt

相关文章

网友评论

      本文标题:[[NSFileManager defaultManager]

      本文链接:https://www.haomeiwen.com/subject/sawivxtx.html