I know about fs.exists(string path) But if I'm in the main directory, and I want to see if you can run "dance" for example, it will return false. Is there a way to see if that file exists on the computer?
Return If File Exists In Any Directory
Started by CCJJSax, Aug 31 2013 01:32 AM
4 replies to this topic
#1
Posted 31 August 2013 - 01:32 AM
#2
Posted 31 August 2013 - 04:03 AM
this is just from my head
function check(dir, file)
f = fs.list(dir)
for k, v in pairs(f) do
local path = fs.combine(dir, v)
if not fs.isReadOnly(path) then
if fs.isDir(path)
check(path) -- check the directory
else
if path == file then
return true
end
end
end
end
that should work
#3
Posted 31 August 2013 - 04:44 PM
jay5476, on 31 August 2013 - 04:03 AM, said:
this is just from my head
function check(dir, file) f = fs.list(dir) for k, v in pairs(f) do local path = fs.combine(dir, v) if not fs.isReadOnly(path) then if fs.isDir(path) check(path) -- check the directory else if path == file then return true end end end endthat should work
Missing one then I'm sure you mean "if fs.isDir(path) then" I'll post more when I have more info on if it worked or not. I'm kinda swamped with stuff to do at the moment.
#4
Posted 31 August 2013 - 05:08 PM
jay5476, on 31 August 2013 - 04:03 AM, said:
this is just from my head
function check(dir, file) f = fs.list(dir) for k, v in pairs(f) do local path = fs.combine(dir, v) if not fs.isReadOnly(path) then if fs.isDir(path) check(path) -- check the directory else if path == file then return true end end end end
You'll also need to pass 'file' to the every recursive call of 'check'.
#5
Posted 31 August 2013 - 07:24 PM
It sounds kind of like shell.resolveProgram is what you're looking for, unless you really need to find it in any directory, rather than just determining if the string input resolves to a file on the path or in the current directory.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











