Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs = fs
- local function readpath( path )
- if fs.isDir( path ) then
- local t = {}
- local files = fs.list( path )
- for i = 1, #files do
- t[files[i]] = readpath( path .. "/" .. files[i] )
- end
- return t
- else
- local h = fs.open( path, "r" )
- if h then
- local content = h.readAll()
- h.close()
- return content
- end
- end
- end
- local function writepath( path, data )
- if type( data ) == "table" then
- fs.makeDir( path )
- for k, v in pairs( data ) do
- writepath( path .. "/" .. k, v )
- end
- elseif type( data ) == "string" then
- local h = fs.open( path, "w" )
- if h then
- h.write( data )
- h.close()
- end
- end
- end
- function redirect( path )
- path = fmtpath( path )
- local device = {}
- local clones = { "combine", "getName", "getDir", "getDrive" }
- for i = 1, #clones do
- device[clones[i]] = fs[clones[i]]
- end
- local single = { "exists", "isDir", "makeDir", "delete", "list", "isReadOnly", "getFreeSpace", "getSize", "open" }
- for i = 1, #single do
- device[single[i]] = function( file, ... )
- return fs[single[i]]( path .. "/" .. file, ... )
- end
- end
- function device.copy( p1, p2 )
- if fs.exists( path .. "/" .. p2 ) then
- return error "path exists"
- end
- writepath( path .. "/" .. p2, readpath( path .. "/" .. p1 ) )
- end
- function device.move( p1, p2 )
- if fs.exists( path .. "/" .. p2 ) then
- return error "path exists"
- end
- writepath( path .. "/" .. p2, readpath( path .. "/" .. p1 ) )
- fs.delete( path .. "/" .. p1 )
- end
- return device
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement