WeBWorK::Utils::Files - contains utility subroutines for files system interaction.
Usage: surePathToFile($start_directory, $path)
Constructs intermediate directories en-route to the file relative to the start directory. The input path can be the path relative to the start directory or can include the start directory.
Usage: readFile($fileName)
Read the entire contents of $fileName
into memory. The file contents are returned after transforming line endings into UNIX line feeds.
listFilesRecusive($dir, $match_qr, $prune_qr, $match_full, $prune_full)
Traverses the directory tree rooted at $dir
, returning a list of files, named pipes, and sockets matching the regular expression $match_qr
. Directories matching the regular expression $prune_qr
are not visited.
$match_full
and $prune_full
are boolean values that indicate whether $match_qr
and $prune_qr
, respectively, should be applied to the bare directory entry (false) or to the path to the directory entry relative to $dir
.
The method returns a list of paths relative to $dir
.
path_is_subdir($path, $dir, $allow_relative)
Ensures that $path
refers to a location "inside" $dir
. If $allow_relative
is true and $path
is not absolute, it is assumed to be relative to $dir
.
The method of checking is rather rudimentary at the moment. First, upreferences ("..") are disallowed in $path
, then it is checked to make sure that some prefix of it matches $dir
.
If either of these checks fails, a false value is returned. Otherwise, a true value is returned.