Jump to content




Attempt to index....?


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

#1 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 03 February 2013 - 11:38 AM

function check(datei)
   term.setTextColour(colors.white)
   write(datei.." ")
   if fs.isDir(datei) then
      term.setTextColour(colors.green)
      print("\(Verzeichnis\)")
   else
      term.setTextColour(colors.orange)
      print("Inhalt:")
      f = io.open(datei, "r")
      data = f:read("*a") 
      f:close()
      print(data)
      term.setTextColour(colors.white)
       if data:find ("shell.run") then
         term.setTextColour(colors.red)
         print("> Found a line with shell.run in "..datei.."!")
         term.setTextColour(colors.white)
      else
         term.setTextColour(colors.lightgreen)
         print("No shell.run in "..data)
         term.setTextColour(colors.white)
      end
   end
   print("")
end

function ReadDir(dir)
 local  dateien = fs.list(dir)
    for i=1,#dateien do
      if fs.isDir(dir) then
         ReadDir(dateien[i])
      end
      check(dateien[i])
  end
end

ReadDir("/")

scan:11: attempt to index? (a nil value)
wat is wrong

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 February 2013 - 11:45 AM

data = f:read("*a")

Should be:

data = f.readAll()

EDIT: No, the error here is that f doesn't exist. Should probably check if f isn't nil first before reading it.

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 03 February 2013 - 11:46 AM

Works fine for me, but I do see a problem arising from your ReadDir function because you're calling ReadDir within itself if dataein[i] is a folder. Remove that just to check if it works.

edit:

View PostKingdaro, on 03 February 2013 - 11:45 AM, said:

data = f:read("*a")

Should be:

data = f.readAll()

EDIT: No, the error here is that f doesn't exist. Should probably check if f isn't nil first before reading it.

No f:read("*a") is the way for io. readAll() is for fs

#4 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 03 February 2013 - 11:58 AM

When removing that just nothing happens ~_~ It prints nothing

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 03 February 2013 - 12:01 PM

I removed only that line and it works fine for me... Check the attachment

#6 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 03 February 2013 - 12:05 PM

Woah, thanks.

Edit: Well I wanted it to check all the directories, but without that I don't know a different way to check all dirs for program. Anyone knows how?

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 03 February 2013 - 12:10 PM

Is yours working yet?

#8 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 03 February 2013 - 12:15 PM

View PostremiX, on 03 February 2013 - 12:10 PM, said:

Is yours working yet?
when removing the line?

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 03 February 2013 - 12:42 PM

I think the problem is that fs.list returns a list of the file names inside a directory, so when using io.open you pass the name of the file, instead of the full path.
this should work:
function ReadDir(dir)
 local dateien = fs.list(dir)
 for i = 1, #dateien do
  local path = fs.combine(dir, dateien[i])
  if fs.isDir(path) then
    ReadDir(path)
  end
  check(path)
 end
end


#10 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 04 February 2013 - 03:39 AM

Now it stops at rom/apis/colors, with the error message: "scan:22: Expected number"

#11 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 04 February 2013 - 04:11 AM

There's no lightgreen color:
term.setTextColour(colors.lightgreen)
It should be:
term.setTextColour(colors.lime)


#12 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 04 February 2013 - 04:27 AM

View PostMysticT, on 04 February 2013 - 04:11 AM, said:

There's no lightgreen color:
term.setTextColour(colors.lightgreen)
It should be:
term.setTextColour(colors.lime)

oopsydaisy





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users