Created
November 22, 2016 04:26
-
-
Save mkhairul/0e4a8b70fc55825b391a9057d0851130 to your computer and use it in GitHub Desktop.
Retrieving countries from filenames from a list of files in a folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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