ULX

Author Topic: file.Find  (Read 2591 times)

0 Members and 1 Guest are viewing this topic.

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
file.Find
« 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.

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: file.Find
« Reply #1 on: January 10, 2020, 10:39:05 PM »
Im guessing that this function is broken since nobody has responded?

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: file.Find
« Reply #2 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])

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: file.Find
« Reply #3 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!!