This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lolcakes64's profile picture

<Request> Wildcard character...

Started by lolcakes64, 20 April 2012 - 06:44 PM
lolcakes64 #1
Posted 20 April 2012 - 08:44 PM
I've tried searching on Google and didn't see anything. I need a wildcard character so I can use it in my better 'list' program I'm making.

I was planning to make it so if a file doesn't have an extension (e.g. .png .mov .txt) at the end of it's name the 'list' command would automatically add '.exe' at the end of it and if it does then list it as is.

Here's a snippet of my code:


  if fs.isDir( sPath ) then
   table.insert( tDirs, sItem .. " dir" )
  else
   if sItem == .. "." .. then
	table.insert( tFiles, sItem )
   else
	table.insert( tFiles, sItem .. ".exe")
   end
  end


If I haven't said enough then feel free to ask me…
Also if it's not a symbol and it's a function or something I'll use that as well
MysticT #2
Posted 20 April 2012 - 08:53 PM
You can use the string API:

local fileName = "test.lua"
if string.find(fileName, ".%..") then
  add_to_list()
end
lolcakes64 #3
Posted 20 April 2012 - 08:59 PM
You can use the string API:

local fileName = "test.lua"
if string.find(fileName, ".%..") then
  add_to_list()
end

Where do you put it? I put it at the start and it error'd me with "attempt to call nil"…
cant_delete_account #4
Posted 20 April 2012 - 10:54 PM
You can use the string API:

local fileName = "test.lua"
if string.find(fileName, ".%..") then
  add_to_list()
end

Where do you put it? I put it at the start and it error'd me with "attempt to call nil"…
Cause add_to_list() isn't a function.
MysticT #5
Posted 20 April 2012 - 11:42 PM
You have to use it in the if. I've modified your code to use it:

if fs.isDir(sPath) then
  table.insert(tDirs, sItem.." dir")
else
  if string.find(sItem, ".%..") then -- use the string.find function here
    table.insert(tFiles, sItem)
  else
    table.insert(tFiles, sItem..".exe")
  end
end
lolcakes64 #6
Posted 20 April 2012 - 11:55 PM
Cool it works now thanks.