Implemented the FileService service in the library target.
This commit is contained in:
1 parent
f6dcc80edc
commit
4d4ce5d647
3 files changed
+39
No files matched your search
@@ -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