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

fs.find wildcards

Started by apemanzilla, 14 April 2014 - 04:27 PM
apemanzilla #1
Posted 14 April 2014 - 06:27 PM
Could anyone provide a list of acceptable patterns and wildcards for use with fs.find? I'm making a pure-Lua implementation of it for one of my projects. All I could find so far was the '*' wildcard.
Lignum #2
Posted 14 April 2014 - 07:40 PM
I don't think there are any others since none are documented on the wiki besides from the asterisk. I have the source in front of me.. but I don't know how regexes work (should I be ashamed?). And I'm assuming it wouldn't be okay to post the source here for someone that understands them to decipher, so I won't.
apemanzilla #3
Posted 14 April 2014 - 07:54 PM
I don't think there are any others since none are documented on the wiki besides from the asterisk. I have the source in front of me.. but I don't know how regexes work (should I be ashamed?). And I'm assuming it wouldn't be okay to post the source here for someone that understands them to decipher, so I won't.
Well I just tested and ? seems to work too…
fs.find("rom/????/gps") finds rom/apis/gps and rom/help/gps…
Edited on 14 April 2014 - 05:55 PM
Wojbie #4
Posted 14 April 2014 - 07:59 PM
Pure guessing here but it would make sense
* - one or more wildcards
? - one wildcard

Wonder if there are other unknown ones.
Edited on 14 April 2014 - 05:59 PM
apemanzilla #5
Posted 14 April 2014 - 08:00 PM
Pure guessing here but it would make sense
* - one or more wildcards
? - one wildcard

Wonder if there are other unknown ones.
Those two are correct, but I'm still trying to see if there are others.
Lignum #6
Posted 14 April 2014 - 08:02 PM
'.' seems to do the same as '?'.
EDIT: There's a Lua implementation of the function in Gamax's version of cclite here on line 687. '?', '.' and '*' seem to be all of them.
Edited on 14 April 2014 - 06:09 PM
apemanzilla #7
Posted 14 April 2014 - 08:04 PM
'.' seems to do the same as '?'.
Could someone try '-'? On my iPad right now.
Lignum #8
Posted 14 April 2014 - 08:09 PM
Could someone try '-'? On my iPad right now.

I've created three files in root named '1', '2' and '3'.

fs.find("[1-3]")

seems to find all of them.
Edited on 14 April 2014 - 06:10 PM
apemanzilla #9
Posted 14 April 2014 - 08:29 PM
Could someone try '-'? On my iPad right now.

I've created three files in root named '1', '2' and '3'.

fs.find("[1-3]")

seems to find all of them.
So I guess it's using string patterns…

Try the same three files and fs.find("%d") please? :P/>
Edited on 14 April 2014 - 06:29 PM
Lignum #10
Posted 14 April 2014 - 08:41 PM
So I guess it's using string patterns…

Try the same three files and fs.find("%d") please? :P/>

Yes, it seems to find all three of them.
MKlegoman357 #11
Posted 14 April 2014 - 08:44 PM
For whatever reason none of them work for me. Only the asterisk (*). But if I'm correct I would say here is a list of what should work.
Lignum #12
Posted 14 April 2014 - 09:22 PM
For whatever reason none of them work for me. Only the asterisk (*). But if I'm correct I would say here is a list of what should work.
That's probably the case since Pattern.compile is what the source code uses.
MKlegoman357 #13
Posted 14 April 2014 - 09:23 PM
Anyone knows why nothing works for me? I'm using CC 1.62.
Lignum #14
Posted 14 April 2014 - 10:04 PM
Anyone knows why nothing works for me? I'm using CC 1.62.
They only seem to work on cclite. I can't use them on CC1.62 either.
apemanzilla #15
Posted 14 April 2014 - 10:06 PM
Anyone knows why nothing works for me? I'm using CC 1.62.
They only seem to work on cclite. I can't use them on CC1.62 either.
Interesting. I'll test more out later.
MKlegoman357 #16
Posted 14 April 2014 - 10:10 PM
Anyone knows why nothing works for me? I'm using CC 1.62.
They only seem to work on cclite. I can't use them on CC1.62 either.

Ah, well that would explain everything :D/>. I thought it was something wrong with my Java. That's why I use MC with real CC to test things. cclite's implementation uses regular Lua's string matching capabilities, so any Lua patterns would work.
apemanzilla #17
Posted 15 April 2014 - 02:55 PM
Alright, in further testing it appears that in regular CC, only the * wildcard is accepted. Others may be available in emulators.