From: <Lar...@re...> - 2006-01-31 15:40:59
|
Tisdag 31 januari 2006 kl 06.27 skrev Andreas Kupries: > I have (over time) collected a set of convenient commands operating > on/with whole files which seem to belong directly into either the > fileutil namespace, or a related namespace, like 'fileutil::FOO'. > > Unfortunately I also have trouble to find a proper name for FOO. Note > that we also might wish to change their names when they go into their > namespace, to remove redundancies ('file'), or have their final names > reflect their behavior more correctly (touch, hack_file). "contents", as suggested, feels appropriate to me (for all except=20 [touch]). An argument for a separate namespace (and accordingly a separate=20 package) is that code needing access to file contents in this manner=20 don't always needs to manipulate metadata and vice versa, but I may be=20= oversensitive there. > Below are the commands collected so far. I would like to get opinions > on whether these commands should really be put into Tcllib, and if > yes, where. > > getfile PATH > > Returns contents of file. Assumes that file is text, > and in system encoding. Then this is the same as [docstrip::util::thefile] (which I don't mind=20= reducing to an alias), except that the latter one takes [fconfigure]=20 options as well. Also, how is this different from [fileutil::cat]? > > I.e. loads the file completely into memory > > putfile PATH TEXT > > Writes text as the new content of the file. > Note: Does _not_ add a traling \n to the data. [getfile] and [putfile] makes me think of the functionalities of=20 [tk_getOpenFile] and [tk_getSaveFile] respectively, so I don't like=20 these names. [fileutil::contents::get] and [fileutil::contents::put]=20 feels OK, however. Also, should fileutil::contents be turned into an=20 ensemble, then I'd much prefer fileutil::contents get ... fileutil::contents put ... > touch PATH > > Creates empty file at PATH. Deletes any pre-existing > file in this location. A [touch] already seems to be in fileutil, with an extensive number of=20= options. > hack_file PATH KEY VAL ... > > Takes the list of keys and values and applies them to > the contents of the file, via [string map]. Do you mean hack_file PATH KEY VAL ?KEY VAL ...? here? Why not a dictionary argument, as in [string map]? In addition, the existing [fileutil::foreachLine] should perhaps be=20 mentioned in this group. It too clearly deals with the contents of=20 files. Lars Hellstr=F6m= |