Last updated at 3:02 pm UTC on 15 January 2016
Iterators and sub-collections. FileMan has iterating code in the following methods:
Rio's equivalent functionality, #entries, #files, #directories, and surprisingly, core functionality such as #isFile, is implemented in terms of a flag #beRecursive and a single iterator #select: (i.e. aRio select: [ :statRecord | <test> ]). For recursing down the tree, the message #all sets #beRecursive.
This approach is flexible, enabling complex custom queries, and the results are Collections suitable for #select:ing and #collect:ing etc.
filesContents := myDirRio all files collect: [ :f | f read contents ].
allTxtFilesThisYear := myDirRio all select: [ :stat | (stat filename endsWith: '.txt') & (stat modificationTime > ('1-1-07' asDate)) ]
FileMan has methods
for finding files according to matchstrings. Rio, has the generic method #select: as described above and a specific #filesMatching: < [array of]matchString>, which is available to match on a set of match strings, a commonly used varient.
FileMan's recursive delete, is provided by setting the #beRecursive flag and using Rio's #delete. i.e .
myDir all delete.
FileMan's file copying utilities are provided by rio, and are more generic.
Rio has specializations (to do) for handling remote files, zip files and archives, as well as an OSProcess specialization which may use native OS facilities if avaiable.
myZipFile zip copyTo: yourDir.
myDir os copyTo: yourDir. Will attempt to use rsync if available.
FileMan's archiveMatching: utility, will be provided by the Rio specialization, invoked via message #zip
FileMan's #at:put provides a simple interface for writing content to files.
Rio's equivalent is not based upon the dictionary interface, but can be similar.
myFileRio < 'Some Content'. - so set a file's content.
(myDirRio / 'file1') < 'Some Content'.
For any serious use via streams the user would be expecting to use the underlying FileDirectory-#newFileNamed: Rio expects that the user will want to access file content via streams as a matter of course. An equivalent of the commonly used method #forceNewFileNamed:, is available by sending #delete or #assureNewFile to the rio before writing.
myFileRio assureNewFile write in: [ :out | out nextPutAll: 'SomeContent' ].