This script defines file utilities and is included in the J standard library. Definitions are loaded into the z locale.
read verbs take a right argument of a filename, optionally linked with one or two numbers (as for 1!:11):
write verbs return number of characters written.
filenames may be open or boxed character or unicode strings
string verbs write out text delimited with the host OS delimiter, and read in text delimited by LF.
on error, the result is _1, e.g. for file not found/file read error/file write error
F | fappend, fappends, fapplylines, fboxname, fcopynew, fdir, ferase, fexist, fgets, fmakex, fpathcreate, fpathname, fread, freadblock, freadr, freads, frename, freplace, fsize, fss, fssrplc, fstamp, ftype, fview, fwrite, fwrite, fwrites |
fboxname | v | fix and box filename |
fgets | v | convert text read from file to J string |
fmakex | v | make file executable |
fpathcreate | v | create a folder path, returning success |
fpathname | v | split file name into path;name |
fstamp | v | returns file timestamp |
fview | v | view file (requires textview) |
fwrite | v | write text to file |
fwrite | v | write text to file if changed |
fwrites | v | write string to file |
Append text to file.
The text is first ravelled. The file is created if necessary.
Returns number of characters written, or an error message.
text fappend filename
'chatham' fappend 'newfile.txt'
7
Append string to file.
The text is first ravelled into a vector with each row terminated by the host delimiter.
The file is created if necessary. Returns number of characters written, or an error message.
Apply verb to lines in file delimited by LF.
Copies files if changed.
tofile fcopynew fromfiles
File directory.
fdir jpath '~system/main/s*.ijs'
Erases a file.
Returns 1 if successful, otherwise _1
Returns 1 if the file exists, otherwise 0.
Read file.
Read block of lines from file.
Lines are terminated by LF.
Blocksize defaults to 1e6
y is filename;start position
returns: block;new start position
Read records from flat file.
y is filename {;record start, # of records}
Records are assumed of fixed length delimited by one (only) of CR, LF, or CRLF.
the result is a matrix of records.
Read file as string.
Renames file.
newname frename oldname
Returns 1 if rename successful.
Replace text in file.
dat freplace file;pos
Returns file size or _1 if error
Search file for string, returning indices.
str fss file
File string search and replace.
(old;new) fssrplc file
Get file type, as: