13 posts
Posted 24 November 2012 - 01:13 PM
This program makes a self-extracting archive from a directory, to make sharing by pastebin easier.
For example:
sfx disk disk.sfx
pastebin put disk.sfx
Then on some other computer on some other server:
pastebin get D0YXE0qX disk.sfx
disk.sfx disk
to get exact copy of the first disk
http://pastebin.com/rxnjypsWSpoiler
tArgs = { ... }
if #tArgs ~= 2 then
print( "Usage= sfx <directory> <archivename>" )
return
end
local sfxFiles = ""
local sfxDirs = ""
root = tArgs[1] .. "/"
function serDir(path)
print("dir " .. root .. path)
local files = fs.list(root .. path)
for _,file in ipairs( files ) do
local fpath = path .. file
if fs.isDir(root .. fpath) then
sfxDirs = sfxDirs .. "\"" .. fpath .. "\",\n"
serDir(fpath .. "/")
else
serFile(fpath)
end
end
end
function serFile(fpath)
sleep(0.05)
print("file " .. root .. fpath)
if fs.getSize(root .. fpath) > 1000000 then
print (root .. fpath .. " is too long, skipping")
else
file = fs.open(root .. fpath, "r")
local text = file.readAll()
file.close()
sfxFiles = sfxFiles .. "\"" .. fpath .. "\",\n\[=====\[" .. text .. "\]=====\]" .. ",\n"
end
end
serDir("")
local sfx = [[
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage= blabla.sfx <dir>" )
return
end
local root = tArgs[1] .. "/"
local files = {
]] .. sfxFiles .. [[
}
local dirs = {]] .. sfxDirs .. [[}
if not fs.isDir(tArgs[1]) then
fs.makeDir(tArgs[1])
end
for _,dir in ipairs(dirs) do
local fpath = root .. dir
print("dir " .. fpath)
if not fs.isDir(fpath) then
fs.makeDir(fpath)
end
end
i = 1
while i<#files do
sleep(0.05)
local fpath = root .. files[i]
local data = files[i+1]
print("file " .. fpath)
local file = fs.open(fpath, "w")
file.write(data)
file.close()
i = i+2
end]]
local file = fs.open(tArgs[2],"w")
file.write(sfx)
file.close()
119 posts
Location
Adelaide, Australia
Posted 25 November 2012 - 09:59 PM
Wow, impressive. :D/>/>
386 posts
Location
France
Posted 26 November 2012 - 03:05 AM
Sorry for my nuub question, but what is the difference with the native copy program ?? No offence it's just that I'm french and don't understand what this do…
715 posts
Posted 26 November 2012 - 12:07 PM
@baturinsky: I didn't test your code, but I'm sure the code will fail at the following line:
function serDir(path)
print("dir " .. root .. fpath) -- <<< This line here
files = fs.list(root .. path)
'fpath' is not defined at that point and thus will be nil there.
And since string and nil cannot be concatenated the code will fail.
I think you probably wanted to write 'path' instead of 'fpath'?
Just wanted to let you know in case you didn't already see it yourself.
13 posts
Posted 28 November 2012 - 12:19 AM
Thanks for feedback, fixed bug with fpath and updated text to make intent of program more clear.
386 posts
Location
France
Posted 28 November 2012 - 04:40 AM
Thanks for feedback, fixed bug with fpath and updated text to make intent of program more clear.
Thanks you, I understand now :P/>
386 posts
Location
France
Posted 29 November 2012 - 05:44 AM
Just tested out, and this is absolutely awesome !!! Good work !!!
1243 posts
Location
Indiana, United States
Posted 29 November 2012 - 10:26 AM
Excellent job here.
116 posts
Posted 30 November 2012 - 12:56 PM
Nice job man, this and a graphical file browser should be standard for CC ;)/>.
451 posts
Location
The left part of this post
Posted 02 December 2012 - 02:44 PM
Im making a program downloader for computercraft like cc-get and i want to know if you can give me your permission to modify your program for using it for my packages
13 posts
Posted 03 December 2012 - 02:39 AM
Im making a program downloader for computercraft like cc-get and i want to know if you can give me your permission to modify your program for using it for my packages
Sure, all my CC code is BSD licensed.