import { promises as Fs } from 'fs' ; import Path from 'path' ; import { app } from 'electron' ; import { FileItem } from '../common/Types' ; param path returns const getFileInfo = async ( path ) : Promise < FileItem > => { const stat = await Fs . stat ( path ) ; return { name : Path . basename ( path ) , path : path , size : stat . size , mode : stat . mode , mtime : stat . mtime . toString ( ) , isDirectory : stat . isDirectory ( ) } ; } ; param folder returns export const enumFiles = async ( folder ? ) : Promise < FileItem [ ] > => { const items = [ ] ; if ( ! folder ) { folder = app . getPath ( 'home' ) ; } const files = await Fs . readdir ( folder ) ; for ( let file of files ) { items . push ( await getFileInfo ( Path . resolve ( folder , file ) ) ) ; } return items ; } ;