Skip to content

Instantly share code, notes, and snippets.

@mkhairul
Created November 22, 2016 04:26
Show Gist options
  • Save mkhairul/0e4a8b70fc55825b391a9057d0851130 to your computer and use it in GitHub Desktop.
Save mkhairul/0e4a8b70fc55825b391a9057d0851130 to your computer and use it in GitHub Desktop.
Retrieving countries from filenames from a list of files in a folder
/*
list of files in a folder
cache/feeds/my_feed.json
cache/feeds/us_feed.json
cache/feeds/uk_feed.json
.....
*/
var glob = require('glob');
var countries = glob.sync('cache/feeds/?([a-z])?([a-z])_feed.json').map(function(obj){
return obj.split('_')[0] // ['cache/feeds/uk', 'feed.json']
.split('/') // ['cache', 'feeds', 'uk']
.pop() // get the last element
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment