32 lines
749 B
Swift
32 lines
749 B
Swift
import Foundation
|
|
|
|
struct FileService: FileServicing {
|
|
|
|
// MARK: Functions
|
|
|
|
func listItems(in folder: String) async throws (FileServiceError) -> [String] {
|
|
let fileManager = FileManager.default
|
|
|
|
guard !folder.isEmpty else {
|
|
throw .folderPathEmpty
|
|
}
|
|
|
|
var isFolder: ObjCBool = false
|
|
|
|
guard fileManager.fileExists(atPath: folder, isDirectory: &isFolder) else {
|
|
throw .folderNotFound
|
|
}
|
|
|
|
guard isFolder.boolValue else {
|
|
throw .folderNotDirectory
|
|
}
|
|
|
|
do {
|
|
return try fileManager.contentsOfDirectory(atPath: folder)
|
|
} catch {
|
|
throw .other(error)
|
|
}
|
|
}
|
|
|
|
}
|