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

后端 未结 5 1335
长发绾君心
长发绾君心 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:34

    For any Swift lovers, coming to this question trying to check if a file is a directory here you go:

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

    (Note that I tried doing return isDir as Bool but it didn't work. But the above Bool initiation seems to work.)

提交回复
热议问题