function deleteFile(File) fs.delete(File) -- Here, I want it to check to see if access is denied. end (Sorry if this isn't too good, I'm copying from code.)
Don't Delete File if Access is Denied.
Started by PixelFox, Apr 13 2015 10:04 PM
10 replies to this topic
#1
Posted 13 April 2015 - 10:04 PM
in the delete function for my file explorer/finder type program, if the person were to delete like, I dunno, some important file, it wouldn't crash the thing, and give me an error, but I want it to keep going, is there a "catch" for C# type thing, I want it to return a variable, and I can't do it, code:
#3
#4
Posted 13 April 2015 - 10:36 PM
It's a tutorial for protected call (pcall), catches the error for you and can tell you if it worked
another is assert
http://www.lua.org/pil/8.3.html
google around for lua error catching
another is assert
http://www.lua.org/pil/8.3.html
google around for lua error catching
Edited by Lupus590, 13 April 2015 - 10:39 PM.
#5
Posted 13 April 2015 - 11:51 PM
You can use fs.isReadOnly for some files, like in the rom, but there are some cases where that won't work, so you should probably just use pcall()
function deleteFile(path) local state,err = pcall(fs.delete,path) --# Pass it a function, then arguments for the function. It returns true/false, then the error if there was one return state endNote that when you pass the function, you DON'T use parenthesis (), since you want to pass the value of the variable (fs.delete), not the result of the function
Edited by HPWebcamAble, 13 April 2015 - 11:52 PM.
#6
Posted 14 April 2015 - 01:34 AM
This function should work great:
otherwise if they delete a file like test it will return true.
function deleteFile(path) if fs.isReadOnly(path) then return false else fs.delete(path) return true end endthis will make it so if they try to delete lets say rom it will return false
otherwise if they delete a file like test it will return true.
#7
Posted 14 April 2015 - 02:31 AM
jakejakey, on 14 April 2015 - 01:34 AM, said:
This function should work great:
otherwise if they delete a file like test it will return true.
function deleteFile(path) if fs.isReadOnly(path) then return false else fs.delete(path) return true end endthis will make it so if they try to delete lets say rom it will return false
otherwise if they delete a file like test it will return true.
That won't work
When a file has been opened by the fs API or somthing similar, deleting it will error, but fs.isReadOnly() can still return false
#8
Posted 14 April 2015 - 01:38 PM
if you want to protect custom files do this:
This should work
By the way, this is my 256th post. 16*16 = 256 and 2^8 = 256, and a lot of other useful stuff
local filesToProtect = {
putPathsHere = true
}
local function newDelete(path)
if filesToProtect[path] then
return false
else
fs.delete(path)
end
end
fs.delete = newDelete
This should work
By the way, this is my 256th post. 16*16 = 256 and 2^8 = 256, and a lot of other useful stuff
Edited by Creator, 14 April 2015 - 01:39 PM.
#9
Posted 14 April 2015 - 02:42 PM
Creator, on 14 April 2015 - 01:38 PM, said:
if you want to protect custom files do this:
This should work
By the way, this is my 256th post. 16*16 = 256 and 2^8 = 256, and a lot of other useful stuff
local filesToProtect = {
putPathsHere = true
}
local function newDelete(path)
if filesToProtect[path] then
return false
else
fs.delete(path)
end
end
fs.delete = newDelete
This should work
By the way, this is my 256th post. 16*16 = 256 and 2^8 = 256, and a lot of other useful stuff
local filesToProtect = {
putPathsHere = true
}
local oldDelete = fs.delete --#Right here
local function newDelete(path)
if filesToProtect[path] then
return false
else
oldDelete(path) --# See i'm calling it here
end
end
fs.delete = newDelete
Edited by Dragon53535, 14 April 2015 - 02:43 PM.
#10
Posted 14 April 2015 - 02:49 PM
Oops, sorry.
#11
Posted 07 June 2015 - 12:34 AM
Lightning, on 13 April 2015 - 10:04 PM, said:
in the delete function for my file explorer/finder type program, if the person were to delete like, I dunno, some important file, it wouldn't crash the thing, and give me an error, but I want it to keep going, is there a "catch" for C# type thing, I want it to return a variable, and I can't do it, code:
function deleteFile(File) fs.delete(File) -- Here, I want it to check to see if access is denied. end (Sorry if this isn't too good, I'm copying from code.)
I solved this problem!
ACESS DENIED occurs when before in your program or in usage of the computer, you are playing to changing or setting other directories..
Look at this example:
if fs.exists("/contas/"..conta.."/emails/"..assunto) then
When i use this, the WORKING directory is now inside the variable "assunto"!So when you try to use
fs.delete("/contas/"..conta.."/emails/"..assunto)
It will try to go into more folders in who are already open!How to Solve? Look:
shell.setDir("/contas/"..conta.."/emails/")
fs.delete("assunto")
Hope this works with you too
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











