220 posts
Location
Germany
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
1688 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.
2088 posts
Location
South 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
is a folder. Remove that just to check if it works.
edit:
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
220 posts
Location
Germany
Posted 03 February 2013 - 11:58 AM
When removing that just nothing happens ~_~ It prints nothing
2088 posts
Location
South Africa
Posted 03 February 2013 - 12:01 PM
I removed only that line and it works fine for me… Check the attachment
220 posts
Location
Germany
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?
2088 posts
Location
South Africa
Posted 03 February 2013 - 12:10 PM
Is yours working yet?
220 posts
Location
Germany
Posted 03 February 2013 - 12:15 PM
Is yours working yet?
when removing the line?
1604 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
220 posts
Location
Germany
Posted 04 February 2013 - 03:39 AM
Now it stops at rom/apis/colors, with the error message: "scan:22: Expected number"
1604 posts
Posted 04 February 2013 - 04:11 AM
There's no lightgreen color:
term.setTextColour(colors.lightgreen)
It should be:
term.setTextColour(colors.lime)
220 posts
Location
Germany
Posted 04 February 2013 - 04:27 AM
There's no lightgreen color:
term.setTextColour(colors.lightgreen)
It should be:
term.setTextColour(colors.lime)
oopsydaisy