You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
LeStorage/LeStorage/Utils/FileManager+Extensions.swift

40 lines
1.2 KiB

//
// FileManager+Extensions.swift
// LeStorage
//
// Created by Laurent Morvillier on 22/04/2024.
//
import Foundation
extension FileManager {
func createDirectoryInDocuments(directoryName: String) -> Bool {
let documentsDirectory = self.urls(for: .documentDirectory, in: .userDomainMask).first!
let directoryURL = documentsDirectory.appendingPathComponent(directoryName)
if !self.fileExists(atPath: directoryURL.path) {
do {
try self.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
} catch {
Logger.error(error)
}
return true
} else {
return false
}
}
func deleteDirectoryInDocuments(directoryName: String) {
let documentsDirectory = self.urls(for: .documentDirectory, in: .userDomainMask).first!
let directoryURL = documentsDirectory.appendingPathComponent(directoryName)
if self.fileExists(atPath: directoryURL.path) {
do {
try self.removeItem(at: directoryURL)
} catch {
Logger.error(error)
}
}
}
}