iphone - how to check if the file is a directory , audio , video or image?

后端 未结 5 1332
长发绾君心
长发绾君心 2021-01-31 02:54

Following my program shows contents of Documents directory and is displayed in a tableView . But the Documents directory contains some directories , some audio , some video , an

5条回答
  •  感情败类
    2021-01-31 03:43

    Updated Evdzhan's answer for Swift 4.0:

    //
    // Check if NSURL is a directory
    //
    func fileIsDir(fileURL: NSURL) -> Bool {
        var isDir: ObjCBool = false;
        FileManager.default.fileExists(atPath: fileURL.path!, isDirectory: &isDir)
        return isDir.boolValue
    }
    
    //
    // Check if a path is a directory
    //
    func fileIsDir(path: String) -> Bool {
        var isDir: ObjCBool = false;
        FileManager.default.fileExists(atPath: path, isDirectory: &isDir)
        return isDir.boolValue
    }
    

提交回复
热议问题