-1

how can i import a folder of images, tried this -

import * as img '../../images';

i want to get all the files inside of the folder and compare them to filenames.

how can i do that? maybe in another why?

oivwndvo
  • 3
  • 2

2 Answers2

0

Have a look on this How to import all modules from a directory in TypeScript?

The way you are trying is not possible.

Check this answer as well Typescript 1.8 modules: import all files from folder

Optimist Rohit
  • 428
  • 6
  • 24
0

You can use fs.readdirSync to read the contents of a directory.

Example:

import fs from "fs"

let images = fs.readdirSync("../../images")

console.log(images)
/* Example output
["sun.png", "stars.jpeg", "icon.psd"]
*/

Documentation

lejlun
  • 4,140
  • 2
  • 15
  • 31