Ask coding questions

← Back to all posts
Loop through a folder?
Zaredo

Lets say I had a folder with many image files stored inside it. Is there a way I could get a file from my code without specifying the name, or loop through each file using a loop so that each file is an index? I am using JavaScript if that helps.

Voters
hchesnier
Zaredo
Comments
hotnewtop
realTronsi

use glob

Coder100

imagine not using fs @realTronsi

realTronsi

@Coder100 glob is better

Coder100

but its a node module @realTronsi

Coder100

this is so hypocritical you like vanilla js but would use glob over native things @realTronsi

realTronsi

@Coder100 fs is a node module too... npm is a package manager vanilla javascript simply means no frameworks or being crap like typescript, but I just dislike frameworks and libs to make other things easier, such as socket.io

Coder100

Sure

and if your file directory looks like:

you will see:

read more

RYANTADIPARTHI

Try using glob

SixBeeps

What @realTronsi said, but here's the link: https://www.npmjs.com/package/glob