This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
karelmikie3's profile picture

help fs.delete() is not working

Started by karelmikie3, 19 December 2012 - 02:30 AM
karelmikie3 #1
Posted 19 December 2012 - 03:30 AM
i got no errors it's simple not deleting
here is my code:


list = fs.list("myPrograms")
fs.makeDir("updater")

progs = {}
version = {}

for number,programs in pairs(list) do
tostring(number)
times_loop = tonumber(number)
progs[number] = programs
end

for i = 1, times_loop do
print(progs)
end

function pastebin()
getVersion()
times_readLine = 1
for i = 1, times_loop do
file2 = fs.open("updater/pastebin", "r")
for a = 1, times_readLine do
file2.readLine()
end
times_readLine = times_readLine + 2
shell.run("pastebin", "get", tostring(file2.readLine()), "updater/"..progs)
file3 = fs.open("updater/"..progs,"r")
file3.readLine()
versionNew = tonumber(file3.readLine())
print(versionNew)
print(version)
if versionNew < version then
if versionNew == version then
shell.resolve()
fs.delete("/updater/"..progs)
elseif
versionNew > version then
shell.resolve()
fs.delete("/myPrograms/"..progs)
fs.copy("/updater/"..progs, "/myPrograms/",progs)
shell.resolve()
fs.delete("/updater/"..progs)
end
end
end
end

function getVersion()
for i =1, times_loop do
file = fs.open("myPrograms/"..progs,"r")
file.readLine()
version = tonumber(file.readLine())
print(progs.." v"..version)
end
end

pastebin()
remiX #2
Posted 19 December 2012 - 03:39 AM
Which part is not deleting? All of it? Or what?

You made a typo: fs.delte("/updater/"..progs) – 'delte'
karelmikie3 #3
Posted 19 December 2012 - 05:21 AM
but the first fs.delete() that is right spellet is also not working
karelmikie3 #4
Posted 19 December 2012 - 05:23 AM
this part:

shell.resolve()
fs.delete("/updater/"..progs)
elseif
versionNew > version then
shell.resolve()
fs.delete("/myPrograms/"..progs)
fs.copy("/updater/"..progs, "/myPrograms/",progs)
shell.resolve()
fs.delete("/updater/"..progs)
remiX #5
Posted 19 December 2012 - 05:42 AM
Add this before it attempts to delete:

fileCheck = fs.open("/updater/" .. progs[i], "r")
if fileCheck then   -- To check if it opens and it's actually there
    fs.delete("/updater/" .. progs[i])
else
    error("Cannot open file: /updater/" .. progs[i])
end[/code

Etc... Are you sure the files actually exist and you spelt them correctly? Try removing the first '/'
Orwell #6
Posted 19 December 2012 - 05:48 AM
Here is your error:

if versionNew < version[i] then
  if versionNew == version[i] then
    // stuff
  elseif versionNew > version[i] then
    // stuff
  end
end
it will never go into the second conditional block because you first require versionNew to be smaller than version then expect it to be equal to or greather than version. Thus the condition will never be fulfilled.
karelmikie3 #7
Posted 19 December 2012 - 06:33 AM
new i got this shell:80: bad argument: string expected, got nil

code


    list = fs.list("myPrograms")
    fs.makeDir("updater")
	
    progs = {}
    version = {}
	
    for number,programs in pairs(list) do
	 tostring(number)
	 times_loop = tonumber(number)
	 progs[number] = programs
    end
	
    for i = 1, times_loop do
	 print(progs[i])
    end
	
    function pastebin()
	 getVersion()
	 times_readLine = 1
	 for i = 1, times_loop do --where do you get this variable?
	  file2 = fs.open("updater/pastebin", "r")
	   for a = 1, times_readLine do
	    file2.readLine() --do you need to be putting these to a variable?
	   end
	  times_readLine = times_readLine + 2
	  shell.run("pastebin", "get", tostring(file2.readLine()), "updater/"..progs[i])
	  file3 = fs.open("updater/"..progs[i],"r")
	  file3.readLine()
	  versionNew = tonumber(file3.readLine())
	  print(versionNew)
	  print(version[i])
	  if versionNew < version[i] or
	  versionNew == version[i] then
	  shell.resolve()
	  fs.delete("updater/"..progs[i])
	  elseif
	  versionNew > version[i] then
	  fs.delete("myPrograms/"..progs[i])
	  fs.copy("updater/"..progs[i], "myPrograms/",progs[i])
	  fs.delete("updater/"..progs[i])
	  end
	 end
    end
	
    function getVersion()
	 for i =1, times_loop do
	  file = fs.open("myPrograms/"..progs[i],"r")
	  file.readLine()
	  version[i] = tonumber(file.readLine())
	  print(progs[i].." v"..version[i])
	 end
    end
	
    pastebin()
Orwell #8
Posted 19 December 2012 - 06:48 AM
This line causes the error and makes no sense at all:

shell.resolve()

What are you trying to do there?
karelmikie3 #9
Posted 19 December 2012 - 07:55 AM
idk i was just trying something to solve it by my self but thanks it works now fine