⛄ Snowberb ⛄ – 13-30 Jul 22

How can I get the file names from a folder inside my project?
S
ScriptyChris636d ago
You mean programatically or how?
S
Sniberb636d ago
yeah
S
Sniberb636d ago
S
Sniberb636d ago
I have this huge logos folder I want to get each file name to create an object dynamically containing those logos So I can later get the src with a function Something like getBookieImageSrc(bookie) you know? @ScriptyChris I dont want to repeat this process every time I put any new image
const images: Bookies = {
'1xbet': '/images/logos/williamhill.webp',
'777es': '/images/logos/williamhill.webp',
'888sport': '/images/logos/williamhill.webp',
aupabet: '/images/logos/williamhill.webp',
bet365: '/images/logos/williamhill.webp',
betfair: '/images/logos/betfair.webp',
bethard: '/images/logos/williamhill.webp',
betsson: '/images/logos/williamhill.webp'
}
const images: Bookies = {
'1xbet': '/images/logos/williamhill.webp',
'777es': '/images/logos/williamhill.webp',
'888sport': '/images/logos/williamhill.webp',
aupabet: '/images/logos/williamhill.webp',
bet365: '/images/logos/williamhill.webp',
betfair: '/images/logos/betfair.webp',
bethard: '/images/logos/williamhill.webp',
betsson: '/images/logos/williamhill.webp'
}
S
ScriptyChris636d ago
Ok, so you are going to need Node (or any backend language, which has access to a file system) In case of Node you can use fs module https://nodejs.org/api/fs.html You can use fs.readdir to list all files inside the logos folder And then to the mapping so file names become images object keys and - this i am not certain due to "williamhill.webp" suffix in your example - like file path be values
S
ScriptyChris636d ago
npm
node-watch
A wrapper and enhancements for fs.watch. Latest version: 0.7.3, last published: 6 months ago. Start using node-watch in your project by running npm i node-watch. There are 821 other projects in the npm registry using node-watch.
S
Sniberb636d ago
oj okay thank you sm!
UU
Unknown User636d ago