COMMUNITY

Folder content in JS

Hi,
I am targeting HTML5 and I’d like to get (recursively) the list of contents of a folder: this must be executed in a macro at compile time because it is a folder containing part of the application code. I can use haxe.io.Path to build a coherent path (I don’t even know if it is necessary, but anyways…), but at this point I should use sys.FileSystem, but I am pretty sure it isn’t supported when targeting JS, right?

image

If so, is there an alternative way to access and read (recursively) the content of a folder at compile-time?

Thanks

Wrap your imports in a #if macro ... #end so that when the file is parsed in “normal mode” (as opposed to macro mode) you don’t get this error.

This make these imports only available in a macro function, which is what you want.
You could also have #if js ... #end or #if !macro ... #end if you wanted to have imports only available for the non macro parts.

Though it’s recommended to not mix (as far as possible) macro code and normal code in the same files, exactly for this reason.

Oh, my… :sweat_smile:
Great! Thank you!