Created
February 15, 2020 05:46
-
-
Save barhoring/e4f139b95326f39e366e66f1f42dba09 to your computer and use it in GitHub Desktop.
prints a directory contents sorted by modification date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const path = require("path"); | |
| const dirName = "./"; | |
| const dirPath = path.join(__dirname, dirName); | |
| fs.readdir(dirPath, function(err, files) { | |
| files = files | |
| .map(function(fileName) { | |
| return { | |
| name: fileName, | |
| time: fs.statSync(dir + "/" + fileName).mtime.getTime() | |
| }; | |
| }) | |
| .sort(function(a, b) { | |
| return -1 * (a.time - b.time); | |
| }) | |
| .map(function(v) { | |
| return v.name; | |
| }); | |
| console.log(files); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This scripts prints the directory content it's in, sorted by modification date
node .\getDirectorySorted.js