Jump to content




Return If File Exists In Any Directory


  • You cannot reply to this topic
4 replies to this topic

#1 CCJJSax

  • Members
  • 262 posts

Posted 31 August 2013 - 01:32 AM

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?

#2 jay5476

  • Members
  • 289 posts

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 CCJJSax

  • Members
  • 262 posts

Posted 31 August 2013 - 04:44 PM

View Postjay5476, 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
that 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 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 31 August 2013 - 05:08 PM

View Postjay5476, 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 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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