📌  相关文章
📜  fs 获取文件夹中的随机文件 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:50.403000             🧑  作者: Mango

代码示例1
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)]