You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.0 KiB

import { readdir } from 'fs/promises'
/**
* getting files
*
* @author Björn Hase
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
* @link https://gitea.node001.net/HerrHase/tellme-bot.git
*
*/
class File {
/**
*
* @param {string} path
*
*/
constructor(path) {
this.path = path
}
/**
* getting alle files from
*
* @param {string} path
* @return {object}
*
*/
async get() {
const result = {
files: [],
errors: false
}
try {
const files = await readdir(this.path, {
withFileTypes: true
})
// run through all files, add options
for (const file of files) {
result['files'].push({
name: file.name,
isDirectory: file.isDirectory()
})
}
} catch (error) {
result['errors'] = error
}
return result
}
}
export default File