⛄ Snowberb ⛄ – 13-30 Jul 22
How can I get the file names from a folder inside my project?
8 Replies
You mean programatically or how?
yeah
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
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 valuesYou might a file watcher for that too
https://nodejs.org/api/fs.html#fswatchfilename-options-listener
or via some library
https://www.npmjs.com/package/node-watch
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.oj okay
thank you sm!
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