Posted 07 October 2014 - 06:20 PM
Hi there,
When I try to use the rename function in my file browser, I get access denied. I am not trying to rename the rom or any read-only folders.
The code is as follows:
What am I doing wrong?
Thanks,
- Sam
When I try to use the rename function in my file browser, I get access denied. I am not trying to rename the rom or any read-only folders.
The code is as follows:
--[[
COPYRIGHT (C) SAMGUNNER 2014.
FILE BROWSER 0.1 IS LICENSED UNDER CREATIVE COMMONS BYNCSA 4.0.
]]--
local args = {...}
local bground = paintutils.loadImage("os8/assets/filemanager/bground")
dir = args[1]
function main()
term.setTextColor(colors.gray)
term.clear()
function backDir()
local path = shell.dir()
local parPath = fs.getDir(path)
if fs.exists(parPath) then
shell.setDir(parPath)
main()
else
main()
end
end
function drawMenu(xPos, yPos, filess, foldss, foldNum)
local var1 = (yPos-(foldNum+2))
if filess[var1] ~= nil then
paintutils.drawLine(xPos,yPos,xPos+10,yPos,colors.blue)
paintutils.drawLine(xPos,yPos+1,xPos+10,yPos+1,colors.blue)
paintutils.drawLine(xPos,yPos+2,xPos+10,yPos+2,colors.blue)
paintutils.drawLine(xPos,yPos+3,xPos+10,yPos+3,colors.blue)
term.setCursorPos(xPos,yPos)
print("FILE MENU")
term.setCursorPos(xPos,yPos+1)
print("Edit")
term.setCursorPos(xPos,yPos+2)
print("Run")
term.setCursorPos(xPos,yPos+3)
print("Rename")
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if button == 1 and x>=xPos and x<=xPos+10 and y==yPos+1 then
shell.run("edit "..filess[var1])
main()
elseif button == 1 and x>=xPos and x<=xPos+10 and y==yPos+2 then
shell.run(filess[var1])
main()
elseif button == 1 and x>=xPos and x<=xPos+10 and y==yPos+3 then
paintutils.drawLine(10,6,40,6,colors.gray)
paintutils.drawPixel(10,7,colors.gray)
paintutils.drawPixel(40,7,colors.gray)
paintutils.drawLine(11,7,39,7,colors.white)
paintutils.drawLine(10,8,40,8,colors.gray)
term.setCursorPos(11,6)
print("Rename")
term.setCursorPos(11,7)
term.setBackgroundColor(colors.white)
local renameName = read()
fs.move(filess[var1],renameName) --# The error occurs here whenever I try to rename the same file more than once in the same instance of computercraft.
main()
else
main()
end
end
else
paintutils.drawLine(xPos,yPos,xPos+11,yPos,colors.blue)
paintutils.drawLine(xPos,yPos+1,xPos+11,yPos+1,colors.blue)
term.setCursorPos(xPos,yPos)
print("Folder Menu")
term.setCursorPos(xPos,yPos+1)
print("Rename")
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if button == 1 and x>=xPos and x<=xPos+10 and y==yPos+1 then
paintutils.drawLine(10,6,40,6,colors.gray)
paintutils.drawPixel(10,7,colors.gray)
paintutils.drawPixel(40,7,colors.gray)
paintutils.drawLine(11,7,39,7,colors.white)
paintutils.drawLine(10,8,40,8,colors.gray)
term.setCursorPos(11,6)
print("Rename")
term.setCursorPos(11,7)
term.setBackgroundColor(colors.white)
local renameName = read()
fs.move(foldss[xPos-2],renameName)
main()
else
main()
end
end
end
end
local dir = "/"..shell.dir()
paintutils.drawImage(bground,1,1)
term.setTextColor(colors.black)
term.setCursorPos(2,1)
print(dir)
term.setCursorPos(3,2)
print("..")
term.setCursorPos(51,1)
print("X")
local lib = fs.list(dir)
local folds = {}
local files = {}
for n, item in pairs(lib) do
if string.sub(item,1,1) ~= "." then
local itemPath = fs.combine(dir,item)
if fs.isDir(itemPath) then
table.insert(folds, item)
else
table.insert(files, item)
end
end
end
local foldNum = 0
table.sort(folds)
table.sort(files)
write("\n")
for n, foldPrint in pairs(folds) do
term.setBackgroundColor(colors.lightGray)
write("[]")
term.setBackgroundColor(colors.white)
foldNum = foldNum+1
write(foldPrint.."\n")
end
for n, filePrint in pairs(files) do
term.setBackgroundColor(colors.lightGray)
write("()")
term.setBackgroundColor(colors.white)
write(filePrint.."\n")
end
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if button == 2 then
if y>1 then
drawMenu(x,y,files,folds,foldNum)
end
elseif button == 1 and x==51 and y==1 then
exit()
elseif button == 1 and x>=1 and x<=51 and y==2 then
backDir()
end
end
end
while true do
main()
end
What am I doing wrong?
Thanks,
- Sam
Edited on 07 October 2014 - 04:22 PM