Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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)] 
 
PREVIOUS NEXT
Tagged: #fs #random #file #folder
ADD COMMENT
Topic
Name
1+9 =