//
//  FileManager+.swift
//  YTBase_Example
//
//  Created by YouT on 2020/9/16.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import Foundation

public extension FileManager {
    //  返回指定目录
    class func getSubDirectoryPathInDocument(_ subDicName: String) -> String {
        let dirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
        if subDicName.isEmpty { return dirPath}
        let reaaDirectoryPath = dirPath + "/" + subDicName
        let fileM = FileManager.default
        var isDir: ObjCBool = ObjCBool(false)
        let isExists = fileM.fileExists(atPath: reaaDirectoryPath, isDirectory: &isDir)
        
        if isExists == false || isDir.boolValue == false {
            // 创建目录
            do {
                try fileM.createDirectory(atPath: reaaDirectoryPath, withIntermediateDirectories: true, attributes: nil)
            } catch  {
                return dirPath
            }
        }
        return reaaDirectoryPath
    }
}
