[swift-users] FileManager alway returns true in Linux

John Smith jsmith5pam at yahoo.com
Fri Mar 10 13:33:04 CST 2017


That is correct as long as the directory “files/“ exists. filename is set to an empty string this your concat statement appends an empty string to your constant string of “files/“ resulting in the path “files/“.


> On Mar 10, 2017, at 1:53 PM, Proyb P via swift-users <swift-users at swift.org> wrote:
> 
> let filename = ""
> let checkfile = FileManager.default
> var isDir : ObjCBool = false
> if checkfile.fileExists(atPath: "files/"+filename, isDirectory: &isDir) {
> print("true")
> } else {
> print("false")
> }
> 
> On Linux, if the "filename" variable is empty string, checkfile will returns as true which should be return as false since the file is not found. macOS is working fine.
> 
> A temporary workarounds is to use
> let filename = "NOTFOUND"
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list