File size: 531 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import { join } from 'path'
import fs from 'fs/promises'
import type { Dirent, StatsBase } from 'fs'
export async function getFilesInDir(path: string): Promise<Set<string>> {
const dir = await fs.opendir(path)
const results = new Set<string>()
for await (const file of dir) {
let resolvedFile: Dirent | StatsBase<number> = file
if (file.isSymbolicLink()) {
resolvedFile = await fs.stat(join(path, file.name))
}
if (resolvedFile.isFile()) {
results.add(file.name)
}
}
return results
}
|