From: Neil M. <ne...@cs...> - 2006-01-31 13:17:42
|
Andreas Kupries wrote: > 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'. I'd vote for directly into the "fileutil" namespace. > getfile PATH > > Returns contents of file. Assumes that file is text, > and in system encoding. > > 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. Perhaps these can be extended to take options like -encoding -translation etc (some suitable subset of [chan configure] options)? > > touch PATH > > Creates empty file at PATH. Deletes any pre-existing > file in this location. I'm with Mark G. Saye on this one -- if it's called "touch" it shouldn't delete a pre-existing file, but just update its atime/mtime. > > appendto PATH DATA > > See putfile, but appends the data to existing > content. Returns the location of the first character > of the appended data in the file. > > insertat PATH AT DATA > > Inserts data at offset AT into the file. > > removeat PATH AT N > > Removes N characters from the file, starting at > offset AT. Again, perhaps [chan configure] options are relevant here? > > hack_file PATH KEY VAL ... > > Takes the list of keys and values and applies them to > the contents of the file, via [string map]. > > hack_file_copy PATHin PATHout KEY VAL ... > > Like hack_file, but writes the result to a different > file. Perhaps mapfile or filemap or even just map (i.e. [fileutil::map]) as it is quite similar to [string map]? The copy version can be done as an option: fileutil map -copy $outfile $infile key val ... -- Neil |