1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
const fs = require('fs') const getFilePathListSortedByTimeStampAsc = dir => { const fileList = [] files = fs.readdirSync(dir) for (const file of files) { const filePath = dir + '/' + file const mtime = fs.statSync(filePath).mtime fileList.push({ filePath: filePath, mtime: mtime }) } return fileList .sort((a, b) => a.mtime - b.mtime) // ASC .map(file => file.filePath) } |