Check if file exists

 Problem

I want to check if a file/folder exists at a specific location.



 Recipe


// Create a FileManager instance

let fileManager = NSFileManager.defaultManager()

// Check if file exists, given its path

if fileManager.fileExistsAtPath("hello.swift") {
    print("File exists")
} else {
    print("File not found")
}
				


 Playground

Find answers here

Hi there! Ask Us a Question We are ready to help