lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 11/02/11 21:02, Luiz Henrique de Figueiredo wrote:
- open(path,"d+") creates a directory
- open(path,"d"[,attributes]) returns an iterator over the directory path,
   returning filenames of existing files matching the attributes table
Interesting but perhaps it is not a good idea to overload open when mkdir
exists and also readdir etc.
mkdir and readdir seem not to exist in the core Lua libraries - at least I did not find them.

I tried not to add new functions, to keep the interface small - however I have no strong opinion with respect to splitting file and directory manipulation into different functiongroups or
maintain them merged together.

I like the io.lines(path) functionality for iterating over files, so I guessed iterating over directories should operate in a similar way, hence open(path,"d") returns an iterator. It could
also be named readdir(path) or anything similar of course.

Note: My proposal, and the Proof-Of-Concept module are named "fs" and containd all functions for file and directory manipulation:, fs.close(), fs.flush(),, fs.write(), ...

io.write() or os.remove() would not necessarily go away, they would rather be wrapped eventually
inside fs.write(), fs.remove().

- remove(path) also removes (empty) directories
os.remove already does that, at least under POSIX. I don't know about Windows.

Perhaps your proposal can be first fleshed out as a working library
so that we evaluate it...

Thats why I offer a Proof-Of-Concept module for the higher level (fs.lua) and the lower level
functions (fsio.lua), see:

Writing a module which reads/writes/iterates over a Lua table should be trivial too and could illustriate some points, e.g. persistence of tables simply by a recursive file copy operation.
Somebody interested?