The I/O APIs are stored in the io
script folder and can be included selectively with the correct require
statement.
The FileSearch interface simplifies the process of searching for files and folders within the file system. Support is provided for both wildcard filters and content searching.
It can be loaded with the line:
require 'io/filesearch'
file.search(Path, Options)
This example searches for text files in the documents:
folder that include the word tennis
:
require 'io/filesearch'
file.search('documents:', {
nameFilter = '*.txt',
nameWild = true,
contentFilter = 'tennis',
maxDepth = 2, -- Only search 2 levels deep
matchFeedback = function(Path, FileName, File)
print(Path, ' ', FileName)
end
})
Valid options to use when defining the search table are as follows:
Option | Description |
---|---|
nameFilter | Include file/folder names that match this filter string or compiled regex object. |
contentFilter | Include files that contain this content. |
nameWild | Set to true to enable Lua pattern matching on nameFilter . Ignored if nameFilter is a regex object. |
contentWild | Set to true to enable Lua pattern matching for contentFilter . |
caseSensitive | Enforces case-sensitive name comparisons if true . |
matchFeedback | Call this function each time that a matched file is discovered. Returning ERR_Terminate will stop the search. Synopsis: function(Path, File, Attributes) |
ignoreFeedback | Call this function each time that a file fails to pass filter matches. |
minSize | Filter out files that do not meet or exceed this minimum size. |
maxSize | Filter out files that exceed this size. |
minDate | Filter out files with a modification time less than this timestamp. |
maxDate | Filter out files with a modification time exceeding this timestamp. |
scanLinks | Allows symbolically linked files and folders to be included in the file search. |
matchFolders | Include matching folder names in the output of the search. |
ignoreFiles | Do not scan files (useful only in conjunction with matchFolders ). |
maxDepth | Maximum depth to recurse into subdirectories (0 = current directory only, 1 = one level deep, etc.). |
When searching files for content, it is strongly recommended that a filter or size limit is applied so that only a limited number of files are opened for searching.
The File Manager API supports common file management needs such as mass file transfer and clipboard operations, and adds integrated UI support so that user interactions are managed in a consistent way across all Parasol applications.
For example, copying a large number of files will pop-up a progress dialog to keep the user informed of progress. If an operation will overwrite an existing file, the user will be notified and given a choice of whether or not to continue.
It can be loaded with the line:
require 'io/filemgr'
error = file.ui.copy(Source, Dest, Move)
Copy the Source
path or paths (if provided as a list of strings) to the file or folder indicated by Dest
.
If Move
is true then each file or folder copied from Source
will be deleted when the copy is successful.
Any errors that occur will be brought to the user's attention with a dialog box. Exceptions will only be thrown if there a catastrophic failure during the copy process. Otherwise, assume that the resulting error
was handled and should only be used as an indicator of the final result. If the user cancels the operation then ERR_Cancelled
is returned.
file.ui.paste(Dest)
Paste files from the clipboard to the destination path. The same behavioural rules for file.ui.copy
apply.
file.ui.delete(Paths)
Delete the identified file or folder at Paths
, which may be a string or list of strings. A progress window is opened if the operation takes longer than expected to run.