Reliable File.Find/FindDir from the running lua file's directory?

Hey guys, a quick one from me; is there any reliable way of using the File.Find/FindDir functions (or similar), relative to the running script file’s directory?
I can think of a way of doing this, namely, putting the script’s filename in a string and then searching for that string from the base directory. I would do that, but it is horribly messy and weak and I hate it.

I want to be able to find the directory of the currently running script, and recursively load all of the lua files in specified subfolders so that I can implement a simple “drag and drop” loading system for objects. This will be in an addon folder but I can’t guarantee the filepath which is why I need this. I can implement the system myself as long as I have a reliable way of finding home.

Advance cheers :v:

This is kind of the same as File.Find("…/lua/"…file), right?

What I’m looking for is a way to resolve a problem where we can’t rely on the script’s filename to determine its directory. Maybe we have multiple files with the same filename in different directories (which will happen in my scenario), or the filename is not concrete. Both of these scenarios endanger or break a recursive search for filename using a ‘hardcoded’ string.

Not exactly. file.FindInLua searches in the downloaded lua cache too.

Untested but I think it should work:
current_file = debug.getinfo( 1 , “nSl” ).source

Thanks a lot, I’ll try this tomorrow and report back with results :smile: