General => Developers Corner => Topic started by: jacksop on January 06, 2020, 08:00:22 PM

Title: file.Find
Post by: jacksop on January 06, 2020, 08:00:22 PM
Hey again, I feel bad like im hogging the forums....

Can't figure out how to add a full directory into the parameter of file.find.

Code: [Select]
local files, directories = file.Find( "addons/help/*", "MOD" )
print( "File: " .. files[1], "Folder: " .. directories[1] )

Error is:

attempt to concatenate a nil value

It works if the directory is "addons/*" but for whatever reason it doesn't when i try to put another folder directory in.

Any ideas? Thanks for your help this week.
Title: Re: file.Find
Post by: jacksop on January 10, 2020, 10:39:05 PM
Im guessing that this function is broken since nobody has responded?
Title: Re: file.Find
Post by: Timmy on January 11, 2020, 01:48:57 AM
Sometimes it might take a little while before you get a response here.

I created a file and a directory in the path you specified (garrysmod/addons/help) and ran your code without issues.

But Lua can't find at least one file and one directory in your path. As a result, when you're printing, you tell Lua to concatenate a string with a filename/directory that does not exist (nil). Lua will throw that concatenation error if you do that.

The print function can deal with nil values if you don't concatenate with those two dots (..). Try this instead:
Code: [Select]
print("First file:", files[1], "First directory:", directories[1])
Title: Re: file.Find
Post by: jacksop on January 11, 2020, 08:27:46 PM
Thanks Timmy. I didn't mean to be rude when i said that. I was spoilt with my last posts to get a response within a day i just assumed something was wrong with using the function.

So I used your code and i got a response. It sees the file, however for whatever reason the "directories" variable returns 'nil'.
For now, ive just removed the directories variable all together because I don't think i need it. Thanks for your help!!