Take this filetree for example:
Dir1
Dir2
program1
program2
program3
I want to be able to return the filepath of Dir1/Dir2/program1, but I don't quite know how to.
Dir1
Dir2
program1
program2
program3
I want to be able to return the filepath of Dir1/Dir2/program1, but I don't quite know how to.
local filepath1 = 'foo'
local filepath2 = 'bar'
-- so if our current directory is "apps"
shell.resolve(filepath1) --> apps/foo
shell.resolve(filepath2) --> apps/bar
local dir = "/"
while true do
local fileList = fs.list(dir)
for i = 1, #fileList do
--generic selection with os.pullEvent()
if fs.isDir(fileList[i]) then
--append dir to be (dir..fileList[i])
else
--open file
--break from loop
end
end
end
local dir = ""
local running=true
while running do
local fileList = fs.list(dir)
table.insert(fileList,1,"../") --insert the "up one" option to the list
for i = 1, #fileList do
--generic selection with os.pullEvent()
local targ=shell.resolve(dir.."/"..fileList[i])
if fs.isDir(targ) then --you had fileList[i] here and that would not work because you would need the full path
dir=targ
else
shell.run(targ)
running=false
break
end
end
end
Well, I finally figured it out on how to navigate through the files fairly easily. I actually did end up going with tables, as it was much easier for me to work with. Here's my unfinished function that I am working on, with the completed navigation:there is a much simpler method in fact. all you do is substitute "../" for the filename. the following code inserts the "up one level" option to the top of the list, normally you would include an if statement like
if shell.resolve(dir)~="" then
so you do not show up one level if they are at the top levellocal dir = "" local running=true while running do local fileList = fs.list(dir) table.insert(fileList,1,"../") --insert the "up one" option to the list for i = 1, #fileList do --generic selection with os.pullEvent() local targ=shell.resolve(dir.."/"..fileList[i]) if fs.isDir(targ) then --you had fileList[i] here and that would not work because you would need the full path dir=targ else shell.run(targ) running=false break end end end
local function newPaste()
for i = 3, y do
paintutils.drawLine(1,i,x,i,colors.lightBlue)
end
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(2, 4)
term.setTextColor(colors.black)
write("File")
term.setCursorPos(19, 4)
write("Type")
term.setCursorPos(30, 4)
write("File Size")
term.setCursorPos(2, 14)
term.setBackgroundColor(colors.lightBlue)
term.setTextColor(colors.black)
write("Selected File Info:")
for k = 15, y do
paintutils.drawLine(2,k,25,k,colors.lightGray)
end
term.setTextColor(colors.black)
term.setBackgroundColor(colors.green)
term.setCursorPos(11,18)
write("Upload")
local scroll = 1
local dirTab = {""}
while true do
local listTable = fs.list(table.concat(dirTab, "/"))
local typeTable = {}
local sizeTable = {}
for i = 1, #listTable do
if fs.isDir(table.concat(dirTab, "/").."/"..listTable[i]) then
table.insert(listTable, 1, listTable[i])
table.remove(listTable, i + 1)
table.insert(typeTable, 1, "Folder")
table.insert(sizeTable, 1, "")
else
table.insert(typeTable, "File")
table.insert(sizeTable, fs.getSize(table.concat(dirTab, "/").."/"..listTable[i]).." Bytes")
end
end
table.insert(listTable, 1, "Return")
table.insert(typeTable, 1, "")
table.insert(sizeTable, 1, "")
for i = 1,8 do
if i > #listTable then break end
if scroll <= 8 then
paintutils.drawLine(1,i + 4,x,i + 4,colors.lightBlue)
term.setCursorPos(1, 4 + i)
term.setBackgroundColor(colors.lightBlue)
term.setTextColor(colors.white)
if fs.isDir(table.concat(dirTab, "/").."/"..listTable[i]) then
term.setTextColor(colors.lime)
write(" "..listTable[i])
elseif listTable[i] == "Return" then
term.setTextColor(colors.green)
write(" "..listTable[i])
else
term.setTextColor(colors.white)
write(" "..listTable[i])
end
term.setCursorPos(19,4 + i)
write(typeTable[i])
term.setCursorPos(30,4 + i)
write(sizeTable[i])
term.setCursorPos(1, 4 + scroll)
term.setTextColor(colors.red)
write(">"..listTable[scroll])
else
paintutils.drawLine(1,i + 4,x,i + 4,colors.lightBlue)
term.setCursorPos(1, 4 + i)
term.setBackgroundColor(colors.lightBlue)
if fs.isDir(table.concat(dirTab, "/").."/"..listTable[scroll + (i - 8)]) then
term.setTextColor(colors.lime)
write(" "..listTable[scroll + (i - 8)])
elseif listTable[scroll + (i - 8)] == "Return" then
term.setTextColor(colors.green)
write(" "..listTable[i])
else
term.setTextColor(colors.white)
write(" "..listTable[scroll + (i - 8)])
end
term.setCursorPos(19, 4 + i)
write(typeTable[scroll + (i - 8)])
term.setCursorPos(30, 4 + i)
write(sizeTable[scroll + (i - 8)])
term.setCursorPos(1, 12)
term.setTextColor(colors.red)
write(">"..listTable[scroll])
end
paintutils.drawLine(3,16,24,16,colors.white)
term.setBackgroundColor(colors.white)
term.setTextColor(colors.blue)
term.setCursorPos(4,16)
if string.len(listTable[scroll]) > 17 then
write(listTable[scroll] == "Return" and "" or string.sub(listTable[scroll], 1,17).."...")
else
write(listTable[scroll] == "Return" and "" or listTable[scroll])
end
end
local events = {os.pullEvent()}
if events[1] == "mouse_scroll" then
if events[2] == 1 then
if scroll >= #listTable then
scroll = #listTable
elseif scroll >= 1 and scroll < #listTable then
scroll = scroll + 1
end
elseif events[2] == -1 then
if scroll <= 1 then
scroll = 1
elseif scroll >= 1 then
scroll = scroll - 1
end
end
elseif events[1] == "key" then
if events[2] == 208 then
if scroll >= #listTable then
scroll = #listTable
elseif scroll >= 1 and scroll < #listTable then
scroll = scroll + 1
end
elseif events[2] == 200 then
if scroll <= 1 then
scroll = 1
elseif scroll >= 1 then
scroll = scroll - 1
end
elseif events[2] == 28 then
if scroll == 1 and dir ~= "/" then
table.remove(dirTab)
scroll = 1
for i = 5,13 do
paintutils.drawLine(1,i,x,i,colors.lightBlue)
end
else
if fs.isDir(table.concat(dirTab, "/").."/"..listTable[scroll]) then
table.insert(dirTab, listTable[scroll])
scroll = 1
for i = 5,13 do
paintutils.drawLine(1,i,x,i,colors.lightBlue)
end
else
if logged then
--add logged upload
else
--not logged upload
end
end
end
end
end
end
end