Skip to content

ubuntunewdev100/npm-random-file

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

select-random-file

Build Status

Select a random file from a provided directory:

const randomFile = require('select-random-file')

const dir = '/tmp/whatever'
randomFile(dir, (err, file) => {
  console.log(`The random file is: ${file}.`)
})

There are a couple of things that could be added:

  • filter files by an extension
  • recursively traverse a deeper directory structure

Acknowledgements

Discussion on Stack Overflow was very useful: http://stackoverflow.com/questions/42425887/how-to-use-an-async-function-as-compare-function-of-array-filter

About

Selects a random file from a directory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%