Because directories are files in macOS and Linux too, I try to determine what type of file it is.
This is the code I have so far:
import Foundation
let filePath = "/Users/Sample/test.ext"
if FileManager.default.isReadableFile(atPath: filePath) {
/// File does exist at this location
}
However, this code does not say whether the file is a regular file or a directory. I thought about using fileType()
to get the exact file type.
Can anyone please help me? I tried a bit but I don't get it working and I am new to Swift.
Thanks in advance.