Sniberb
Sniberb3y ago

⛄ Snowberb ⛄ – 13-30 Jul 22

How can I get the file names from a folder inside my project?
8 Replies
ScriptyChris
ScriptyChris3y ago
You mean programatically or how?
Sniberb
SniberbOP3y ago
yeah
Sniberb
SniberbOP3y ago
Sniberb
SniberbOP3y 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'
}
ScriptyChris
ScriptyChris3y 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
ScriptyChris
ScriptyChris3y 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.
Sniberb
SniberbOP3y ago
oj okay thank you sm!
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1000032048855138364