dir->moveTo

Moves a directory.

Target member

Signature

1dir->moveTo(path::string)

Moves a directory.

dir->moveTo is called with member syntax on a receiver value. dir->moveTo touches paths or filesystem data. Resolve paths deliberately and avoid mixing visitor-provided path fragments with trusted server paths without validation.

Parameters

path
Required value of type string. Supply path positionally unless the signature shows a keyword form.

In web-serving modes, request-targeted application file access cannot escape the configured document_root. That boundary can come from the .ini file, the --docroot flag used by the LaiRu HTTP server or FPM process, or FastCGI values such as DOCUMENT_ROOT and SCRIPT_FILENAME supplied by nginx or Apache. See the web root directory, FastCGI options, and LaiRu FPM pages for the deployment side of that boundary.

Examples

Basic call

1dir('/tmp/a')->moveTo('/tmp/b')
The example assumes a trusted path. Validate or resolve any path built from visitor input.

List files beneath a configured directory

1[2local(root) = dir('/var/www/html/assets')3if(#root->exists) => {4    #root->eachFilePath => {5        local(f) = file(#1)6        #f->path + ' ' + #f->size + '\n'7    }8}9]
Directory traversal should start from a known server-side root, not from an unchecked visitor-supplied path.

Recursive traversal with an explicit base

1[2local(base) = '/var/www/html/content'3dir(#base)->eachPathRecursive => {4    local(path) = string(#1)5    if(not #path->contains('/.')) => {6        #path + '\n'7    }8}9]
When walking recursively, keep the base path explicit and filter hidden or generated directories deliberately.

Related