Problem with file.Find, it finds files in every addons...

Hi guys,

I have a problem with file.Find. When I use it to find files in my addon’s materials folder, it also find materials of every other add-ons…

local MaterialList  = file.Find( "../materials/*.vmt" )


This example prints every .vmt that are in a folder named “materials”, no matter in which add-on…

How do I restrict it to only my add-on ?

Thanks you.


But what if people change the folder’s name of my addon?

Also I have to add that this list of materials will be downloaded by clients using resource.AddFile

Make a unique folder to put your materials in. e.g.


Well ok, if that’s the unique solution I’ll do that then :wink:

But there isn’t a better way? Like, a function to retrieve the addon’s name so I can do like Jinto said?

Something similar to debug.getinfo(2, “S”).short_src, which retrieve the name of the current script’s file…

util.RelativePathToFull on the debug.getinfo thing. Then a little bit of pattern matching to get the folder name.

I tried anything I could think of, nothing worked…

Well, for materials it’s ok I guess, I just put my materials in a subfolder as Chief Tiger wrote.

But what about fonts? They NEED to be in folder “resource/fonts”, I can’t put them in a subfolder such as “resource/fonts/myaddon” or they aren’t loaded in the game (those fonts are downloaded by clients).

So I need to find my addon folder’s name, but what you suggested FlapJack, didn’t work :frowning:

Why do you need to find all the fonts there? I mean when you add the fonts, you know they are there, so you can access them directly.

I want to list all fonts in my addon’s “resource/fonts” folder, to send them to clients. So I -and users of my addon- can add or remove fonts, without modifying the script.

But same problem as in the first post, if I do

local FontsList  = file.Find( "../resource/fonts/*.ttf" )

It will find fonts in other addons as well, which is what I don’t want.

I need to find my addon’s folder name so I can do:

local FontsList  = file.Find( "../addons/<myfolder>/resource/fonts/*.ttf" )

without worrying about users renaming it.

PS: I doubt there is many addons that have a “resource/fonts” inside them, but still it’s a little problem I would like to be solved…

But what I don’t get is that you actually try to make a list while in-game when you can make it trough Explorer.

make a static list before you release your addon. It’ll be faster and there’s no need to make a new list every bootup when the content isn’t going to change.


Like has been said, make your list ahead of time.

Sorry I don’t understand what you mean…

This list is used to send every fonts to clients.

local FontsPath		= "resource/fonts/"
local FontsList		= file.Find( "../" .. FontsPath .. "*.ttf" )

for _, v in ipairs(FontsList) do
    resource.AddFile( FontsPath .. v )

and then I also use this list as options in a ComboBox of my STOOL’s control panel.

So if I add or remove fonts from the folder, then they are automatically added or removed from the FontsList, and the content of the ComboBox = the content of the folder.

This addon isn’t only for me, once it’s done I would like to share it and people who use it can then add their own fonts (and materials) easily, just by dropping them in the folder. So I can’t make a static list…

I’m not sure I fully understand.
You’re making a STool that adds files to the resource list?

Maybe hes making some 3D2D text STool or something where he want a combo box to set font? I have a line for getting the addon folder somewhere here…

Exactly, Tobba

Please find that line :wink: