[swift-users] FileManager alway returns true in Linux

Marco S Hyman marc at snafu.org
Fri Mar 10 14:45:54 CST 2017


> On Mar 10, 2017, at 12:32 PM, Proyb P via swift-users <swift-users at swift.org> wrote:
> 
> MacOS shown different behavior.

Running a playground using Xcode 8.2.1 on macOS 10.12.3 your code returns true and the isDir value is also true.

Are you sure the directory “files” exists on your macOS test environment?

let filename = ""
let checkfile = FileManager.default
var isDir : ObjCBool = false

if checkfile.fileExists(atPath: "."+filename, isDirectory: &isDir) {
    print("true, directory = \(isDir)")
} else {
    print("false")
}

results in this output: "true, directory = true”

Marc


More information about the swift-users mailing list