2

Is there a way to loop through some files in script tag in html head section?

I am looking for something like this:

<head>
  <script>
   let path = './areas/js/build/bundles/";
   foreach(file in path) {
    // do something
   }
  </script>
</head>

There are some dynamically created bundles that I need to loop through them in my script tag of my html file.

Thanks for your help

AlreadyLost
  • 767
  • 2
  • 13
  • 28

1 Answers1

3

You can't in Javascript. For security reasons, you cannot access a user's file system - even if it's your own.

What you want to achieve is done with back-end technologies such as PHP, ASP.net, etc, etc.

In PHP, you would do something like:

foreach (new DirectoryIterator('./areas/js/build/bundles/') as $fileInfo) {
    echo $fileInfo->getFilename();
}
Martin James
  • 902
  • 1
  • 9
  • 25