Implemented the FileService service in the library target.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user