Moved BindingGenerator from gen html project. It makes more sense here.

This commit is contained in:
2025-10-25 00:06:22 -04:00
parent 58a8419984
commit 603a0aa0e3
141 changed files with 12738 additions and 7 deletions

View 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
}
}