i am trying to download a file use it and delete it again to make space on the hard drive for the next file but i does not delete the file somehow:
local c = require("component")
local computer = require("computer")
local internet = require("internet")
local fs = require("filesystem")
local p = c.printer3d
args = {...}
link = "https://raw.githubusercontent.com/LordNocturnus/sf-"
folder = "/master/"
imax = 0
local TIMEOUT = 4 -- in seconds
for i = 0, imax do
local url = link .. i .. folder .. "list.txt"
local status, connection = pcall(internet.request, url)
if not status or not connection then
print("Download of " .. url .. " failed.")
else
local startTime = computer.uptime()
while true do
local response, isFinished = pcall(connection.finishConnect)
if response and isFinished then
local f = io.open("list.txt", "wb")
-- print(status)
-- print(response)
print(isFinished)
-- print(connection)
for chunk in connection do
f:write(chunk)
end
f:close()
break
elseif computer.uptime() - startTime > TIMEOUT then
print("Request to " .. url .. " timed out")
os.exit()
else
os.sleep(0.25)
end
end
end
for line in io.lines('list.txt') do
print(line)
local url = link .. i .. folder .. line .. ".mb3d"
local status, connection = pcall(internet.request, url)
if not status or not connection then
print("Download of " .. url .. " failed.")
else
local startTime = computer.uptime()
while true do
local response, isFinished = pcall(connection.finishConnect)
if response and isFinished then
local f = io.open(line .. ".mb3d", "wb")
-- print(status)
-- print(response)
print(isFinished)
-- print(connection)
for chunk in connection do
f:write(chunk)
end
f:close()
break
elseif computer.uptime() - startTime > TIMEOUT then
print("Request to " .. url .. " timed out")
os.exit()
else
os.sleep(0.25)
end
end
end
cords = {}
for i in string.gmatch(line,"([^-]+)") do
cords[#cords+1] = tonumber(i)
end
print(cords[1],cords[2],cords[3])
-- printer(cords[1],cords[2],cords[3]) -- do something with the file
file = string.format("%d-%d-%d.mb3d", cords[1],cords[2],cords[3])
fs.remove(file)
end
end
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Hello
i am trying to download a file use it and delete it again to make space on the hard drive for the next file but i does not delete the file somehow:
local c = require("component")
local computer = require("computer")
local internet = require("internet")
local fs = require("filesystem")
local p = c.printer3d
args = {...}
link = "https://raw.githubusercontent.com/LordNocturnus/sf-"
folder = "/master/"
imax = 0
local TIMEOUT = 4 -- in seconds
for i = 0, imax do
local url = link .. i .. folder .. "list.txt"
local status, connection = pcall(internet.request, url)
if not status or not connection then
print("Download of " .. url .. " failed.")
else
local startTime = computer.uptime()
while true do
local response, isFinished = pcall(connection.finishConnect)
if response and isFinished then
local f = io.open("list.txt", "wb")
-- print(status)
-- print(response)
print(isFinished)
-- print(connection)
for chunk in connection do
f:write(chunk)
end
f:close()
break
elseif computer.uptime() - startTime > TIMEOUT then
print("Request to " .. url .. " timed out")
os.exit()
else
os.sleep(0.25)
end
end
end
for line in io.lines('list.txt') do
print(line)
local url = link .. i .. folder .. line .. ".mb3d"
local status, connection = pcall(internet.request, url)
if not status or not connection then
print("Download of " .. url .. " failed.")
else
local startTime = computer.uptime()
while true do
local response, isFinished = pcall(connection.finishConnect)
if response and isFinished then
local f = io.open(line .. ".mb3d", "wb")
-- print(status)
-- print(response)
print(isFinished)
-- print(connection)
for chunk in connection do
f:write(chunk)
end
f:close()
break
elseif computer.uptime() - startTime > TIMEOUT then
print("Request to " .. url .. " timed out")
os.exit()
else
os.sleep(0.25)
end
end
end
cords = {}
for i in string.gmatch(line,"([^-]+)") do
cords[#cords+1] = tonumber(i)
end
print(cords[1],cords[2],cords[3])
-- printer(cords[1],cords[2],cords[3]) -- do something with the file
file = string.format("%d-%d-%d.mb3d", cords[1],cords[2],cords[3])
fs.remove(file)
end
end
Link to post
Share on other sites