1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
-- Copyright (C) 2007-2014 by Ubaldo Porcheddu <ubaldo@eja.it>
-- from eja.c
-- function ejaFileStat(p) end
-- function ejaDirList(d) end
-- function ejaDirCreate(d) end
function ejaFileCheck(f)
if ejaFileStat(f) then
return true
else
return false
end
end
function ejaFileRead(f)
local x=io.open(f,'r')
local data=''
if x then
data=x:read('*a')
x:close()
return data
else
return false
end
end
function ejaFileWrite(f,data)
local x=io.open(f,'w')
if not data then data='' end
if x then
x:write(data)
x:close()
return true
else
return false
end
end
function ejaFileAppend(f,data)
local x=io.open(f,'a')
if x then
x:write(data or '')
return x:close()
else
return false
end
end
function ejaFileSize(f)
local fd=io.open(f,'r')
if fd and fd:read(1) then
size=fd:seek('end')
fd:close()
return size
else
return -1
end
end
function ejaFileCopy(fileIn,fileOut)
ejaExecute('cp "'..fileIn..'" "'..fileOut..'"')
end
function ejaFileRemove(f)
ejaExecute('rm -f "'..f..'"')
end
function ejaFileMove(old, new)
ejaExecute('mv "'..old..'" "'..new..'"')
end
function ejaFileLoad(f)
local ejaScriptRun=assert(loadfile(f))
if ejaScriptRun then ejaScriptRun() end
end
function ejaDirListSort(d) --sort alphabetically
local t=ejaDirList(d)
if type(t) == 'table' then
table.sort(t)
return t
else
return false
end
end
function ejaDirTable(d) --return list as array
local t=ejaDirList(d)
local tt={}
if t then
for k,v in next,t do
if not v:match('^%.$') and not v:match('^%.%.$') then
tt[#tt+1]=v
end
end
end
return tt
end
function ejaDirTableSort(d)
local t=ejaDirTable(d)
table.sort(t)
return t
end
function ejaDirListSafe(d) --no hidden files
local t=ejaDirList(d)
local tt={}
if t then
for k,v in next,t do
if v:match('^[^.]') then
tt[#tt+1]=v
end
end
return tt
else
return false
end
end
function ejaDirCreatePath(p)
local path=''
local r=false
if not p:match('^/') then path='.' end
for k in p:gmatch('[^/]+') do
path=path..'/'..k
if not ejaFileStat(path) then
r=ejaDirCreate(path)
end
end
return r
end
function ejaDirTree(path)
local out=''
for k,v in next,ejaDirTable(path) do
local x=ejaFileStat(path..'/'..v)
if x then
out=out..ejaSprintf('%10s %06o %s %s\n',x.mtime,x.mode,x.size,path..'/'..v)
if ejaSprintf('%o',x.mode):sub(-5,1)=='4' then out=out..ejaDirTree(path..'/'..v) end
end
end
return out
end
|