Moved BindingGenerator from gen html project. It makes more sense here.
This commit is contained in:
33
Sources/BindingGenerator/Extensions/FileManager+Ext.swift
Normal file
33
Sources/BindingGenerator/Extensions/FileManager+Ext.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// FileManager+Ext.swift
|
||||
// gen_html
|
||||
//
|
||||
// Created by Isaac Paul on 4/30/25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension FileManager {
|
||||
//TODO: should also check if url is file
|
||||
func listFiles(_ directory:URL, withLowercaseExtensions:[String] = [], recursive:Bool = false) throws -> [URL] {
|
||||
let options:FileManager.DirectoryEnumerationOptions = recursive ? [] : [.skipsSubdirectoryDescendants]
|
||||
let fileIterator = try self.contentsOfDirectory(at: directory, includingPropertiesForKeys: [.isDirectoryKey], options: options)
|
||||
let filesOnly = fileIterator.filter { (url) -> Bool in
|
||||
do {
|
||||
let resourceValues = try url.resourceValues(forKeys: [.isDirectoryKey])
|
||||
let isDirectory = resourceValues.isDirectory ?? true
|
||||
if (isDirectory) {
|
||||
return false
|
||||
}
|
||||
} catch { return false }
|
||||
|
||||
if withLowercaseExtensions.count > 0 {
|
||||
let pathExt = url.pathExtension.lowercased()
|
||||
let contains = withLowercaseExtensions.firstIndex(of: pathExt)
|
||||
return contains != nil
|
||||
}
|
||||
return true
|
||||
}
|
||||
return filesOnly
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user