Answers for "fs get random file in folder"

0

fs get random file in folder

var fs = require('fs');
var files = fs.readdirSync('/path/to/dir/')
/* now files is an Array of the name of the files in the folder and you can pick a random name inside of that array */
let chosenFile = files[Math.floor(Math.random() * files.length)]
Posted by: Guest on May-07-2021

Browse Popular Code Answers by Language