Search
 
SCRIPT & CODE EXAMPLE
 

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)] 
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript array to comma separated string 
Javascript :: copy text to clipboard javascript react 
Javascript :: how to check if object is empty javascript 
Javascript :: get link js 
Javascript :: local storage check max size 
Javascript :: js get url params 
Javascript :: random color in javascript 
Javascript :: for key value in object javascript 
Javascript :: NullInjectorError: No provider for HttpHandler! 
Javascript :: get selected text js 
Javascript :: ng build JS stacktrace 
Javascript :: hello world expressjs 
Javascript :: missing from-clause entry for table sequelize limit 
Javascript :: jquery left arrow key press 
Javascript :: how to detect the keyboard keys in js 
Javascript :: js check for class in classList 
Javascript :: This version of CLI is only compatible with Angular versions 0.0.0 || ^10.0.0-beta || =10.0.0 <11.0.0, but Angular version 9.1.3 was found instead. 
Javascript :: Codewars Beginner - Reduce but Grow 
Javascript :: keyup multiple fields 
Javascript :: get url query params js 
Javascript :: javascript check if value exists in array of objects 
Javascript :: javascript detect scroll to bottom of page 
Javascript :: document getelementsbyclassname not getting all elements 
Javascript :: div outside click event jquery 
Javascript :: waypoint cdn 
Javascript :: kubectl get pod by node 
Javascript :: rollup is not inlining core-js 
Javascript :: how to get the data attached with an element in javascript 
Javascript :: javascript howto get xhr 
Javascript :: simple AES encryption javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =