2 FFLuCI - Filesystem tools
5 A module offering often needed filesystem manipulation functions
11 Copyright 2008 Steven Barth <steven@midlink.org>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
27 module("ffluci.fs", package.seeall)
31 -- Checks whether a file exists
32 function isfile(filename)
33 local fp = io.open(path, "r")
34 if file then file:close() end
38 -- Returns the content of file
39 function readfile(filename)
40 local fp, err = io.open(filename)
46 local data = fp:read("*a")
51 -- Returns the content of file as array of lines
52 function readfilel(filename)
53 local fp, err = io.open(filename)
63 if (line == nil) then break end
64 table.insert(data, line)
71 -- Writes given data to a file
72 function writefile(filename, data)
73 local fp, err = io.open(filename, "w")
81 -- Returns the file modification date/time of "path"
83 return posix.stat(path, "mtime")
87 basename = posix.basename
90 dirname = posix.dirname
92 -- Diriterator - alias for lfs.dir - filter . and ..
94 local e = posix.dir(path)
100 -- Alias for lfs.mkdir