--file system
local function fList(dir)
term.clear()
frame()
local n = 1
local _list = fs.list(dir)
for i = 1, #_list do
term.setCursorPos(3, i + 4)
write(" ".._list[i].." ")
end
term.setCursorPos(3, 5)
write("[".._list[1].."]")
while true do
local event, p1, p2 = os.pullEvent()
if event == "key" and p1 == 200 then --up
if n == 1 then
n = 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n - 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 208 then --down
if n == #_list then
n = #_list
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n + 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 28 or p1 == 156 then
break
end
end
return _list[n]
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Can't browse through ROM folders
Started by Cranium, 14 November 2012 - 07:18 AMPosted 14 November 2012 - 08:18 AM
For some reason, on my file browsing function, I can't browse through the ROM folder beyond the initial directory. When I select it, it thinks that each folder, like the APIs, Programs, and everything in ROM that is supposed to be a directory is a file, not a folder. Is there something that I did wrong on the function?
Posted 14 November 2012 - 08:27 AM
I had the same issue as you with my browser. test it with browsing into a folder structure you create on the computer. it won't work there either… it is because you are not including the full path in the variable dir, you just have the filename. (once in rom and you try to open programs the dir variable becomes programs when it should be rom/programs)
Posted 14 November 2012 - 08:56 AM
So I would want to do
if fs.isDir(dir.."/".._list[n]) then
Right? Or how would I resolve the full path?Posted 14 November 2012 - 09:04 AM
that should work. or try
shell.resolve(_list[n])
Posted 14 November 2012 - 09:16 AM
Well I can't test right now, but I think this modification should work based on what you're telling me:
--file system
local function fList(dir)
term.clear()
frame()
local n = 1
local _list = fs.list(dir)
for i = 1, #_list do
term.setCursorPos(3, i + 4)
write(" ".._list[i].." ")
end
term.setCursorPos(3, 5)
write("[".._list[1].."]")
while true do
local event, p1, p2 = os.pullEvent()
if event == "key" and p1 == 200 then --up
if n == 1 then
n = 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n - 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 208 then --down
if n == #_list then
n = #_list
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n + 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 28 or p1 == 156 then
break
end
end
local fReturn = _list[n]
if fs.isDir(shell.resolve(fReturn)) then
local fReturn = fList(fReturn)
else
return fReturn
end
end
Posted 14 November 2012 - 09:31 AM
I won't say it'l work for fear of being wrong :P/>/> but I know that I had the same issue with my browser. I recommend you add a print function to show you the full file path before it tries to use it in your code so you can see if it is formatted right
EDIT: if you PM me your full code I would be happy to test it for you
EDIT: if you PM me your full code I would be happy to test it for you
Posted 14 November 2012 - 10:13 AM
corrected code: just had to make it pass the current dir to the re-iteration
--file system
local function fList(dir)
dir=shell.resolve(dir)
term.clear()
frame()
local n = 1
local _list = fs.list(dir)
table.sort(_list)
for i = 1, #_list do
term.setCursorPos(3, i + 4)
write(" ".._list[i].." ")
end
term.setCursorPos(3, 5)
write("[".._list[1].."]")
while true do
local event, p1, p2 = os.pullEvent()
if event == "key" and p1 == 200 then --up
if n == 1 then
n = 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n - 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 208 then --down
if n == #_list then
n = #_list
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
elseif n >= 1 then
term.setCursorPos(3, n + 4)
write(" ".._list[n].." ")
n = n + 1
term.setCursorPos(3, n + 4)
write("[".._list[n].."]")
end
elseif event == "key" and p1 == 28 or p1 == 156 then
break
end
end
local fReturn = _list[n]
if fs.isDir(shell.resolve(dir..'/'..fReturn)) then
local fReturn = fList(shell.resolve(dir..'/'..fReturn))
else
return fReturn
end
end