currentdir = "/"
while true do
print(currentdir)
print("")
list = fs.list(currentdir)
for i = 1, #list do
print(i .. ": " .. list[i])
end
a, b = os.pullEvent("char")
if b == "0" then
currentdir = ".." -- Here is the problem
else
if fs.isDir(list[tonumber(:)/>/>]) then
currentdir = list[tonumber(:D/>/>]
else
shell.run(list[tonumber(:D/>/>])
end
end
end
Going up?
#1
Posted 17 November 2012 - 11:44 PM
#2
Posted 17 November 2012 - 11:58 PM
#3
Posted 17 November 2012 - 11:59 PM
#4
Posted 18 November 2012 - 12:37 AM
s = "rom/programs"
print(s)
for k, v in string.gmatch(s, "(%w+)/(%w+)") do
z = k
end
print(s) -- Output: "rom/programs" print(z) -- Output: "rom"
EDIT:
This actually works better
t = {}
dir = "rom/programs"
for token in string.gmatch(dir, "(%w+)") do
table.insert(t, token)
end
for i = 1, #t do
print(t[i])
end
Output:
rom programs
#5
Posted 18 November 2012 - 12:53 AM
sIdEkIcK_, on 18 November 2012 - 12:37 AM, said:
s = "rom/programs" print(s) for k, v in string.gmatch(s, "(%w+)/(%w+)") do z = k end
print(s) -- Output: "rom/programs" print(z) -- Output: "rom"
EDIT:
This actually works better
t = {}
dir = "rom/programs"
for token in string.gmatch(dir, "(%w+)") do
table.insert(t, token)
end
for i = 1, #t do
print(t[i])
end
Output:
rom programs
I dont get that though
I need to set a variable's value to the previous directory
#6
Posted 18 November 2012 - 12:56 AM
dir = "rom/programs"
w = string.split(dir, "/") -- The second argument is the pattern that the dir has, which is /
-- this function returns as a table
for i = 1, #w do
print(w[i])
end
Output:
rom
programs
#7
Posted 18 November 2012 - 01:05 AM
shell.setDir(x)work?
#8
Posted 18 November 2012 - 01:10 AM
sIdEkIcK_, on 18 November 2012 - 12:56 AM, said:
dir = "rom/programs" w = string.split(dir, "/") -- The second argument is the pattern that the dir has, which is / -- this function returns as a table for i = 1, #w do print(w[i]) end Output: rom programs
Attempt to call nil on:
sIdEkIcK_, on 18 November 2012 - 12:56 AM, said:
tiin57, on 18 November 2012 - 01:05 AM, said:
shell.setDir(x)work?
#9
Posted 18 November 2012 - 01:20 AM
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: cd <path>" )
return
end
local sNewDir = shell.resolve( tArgs[1] )
if fs.isDir( sNewDir ) then
shell.setDir( sNewDir )
else
print( "Not a directory" )
return
end
So this should work :
shell.setDir(shell.resolve( ".." ))
#10
Posted 18 November 2012 - 04:52 AM
Mr CC geek, on 18 November 2012 - 01:10 AM, said:
sIdEkIcK_, on 18 November 2012 - 12:56 AM, said:
dir = "rom/programs" w = string.split(dir, "/") -- The second argument is the pattern that the dir has, which is / -- this function returns as a table for i = 1, #w do print(w[i]) end Output: rom programs
Attempt to call nil on:
sIdEkIcK_, on 18 November 2012 - 12:56 AM, said:
It should... do you have 'dir' defined?
#11
Posted 18 November 2012 - 10:48 AM
path = string.match(path, "(.*)/[^/]+$")
#12
Posted 18 November 2012 - 10:52 AM
cd ../on the command line, if you're in afolder/anotherfolder/, should send you to afolder/. In a lua script, it'd be
shell.setDir('../')
EDIT: forums what the hell have you done with my periods.
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











