Created
July 23, 2018 10:24
-
-
Save mkatychev/18978512cd67f15ec0e0fd653b37dfeb to your computer and use it in GitHub Desktop.
Simple script to import files as variables from a predetermined filepath (quite useful for media folders with tons of pictures and the like)
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
import fs | |
const fs = require('fs'); | |
function importFiles(x,y) { | |
fs.readdir(x, (err, files) => { | |
files.forEach(file => { | |
var doc = file | |
var char = /.+(?=\.\w+)/.exec(file); | |
if (char !== null) { | |
eval(y + char + " = " + "'" + String(x + doc) + "'"); | |
} | |
}); | |
}) | |
} | |
importFiles('../public/img/', 'img'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment