Goto main content


Use to remove directories and files.



remove - Used to remove directories and files.


remove([recursive:true|false,] "directory or file or pattern");


This function is used to remove directories, files or patterns.

If you want to remove the directories even if they are not empty, set the "recursive" parameter to true to remove everything.

Removing a non existing directory, file or pattern is silently ignored.

Removing a non empty directory produces an error unless recursive is set to true.

A pattern can be used to specify multiple files:

PATTERN: Backslash followed by any character, including another backslash. MATCHES: That character exactly.

PATTERN: ? MATCHES: Any single character.

PATTERN: * MATCHES: Any sequence of zero or more characters. (Note that multiple *s in a row are equivalent to one.)

PATTERN: Any character other than \?*[ or a \ at the end of the pattern MATCHES: That character exactly. (Case sensitive.)

PATTERN: [ followed by a class description followed by ] MATCHES: A single character described by the class description. (Never matches, if the class description reaches until the end of the string without a ].) If the first character of the class description is or !, the sense of the description is reversed. The rest of the class description is a list of single characters or pairs of characters separated by -. Any of those characters can have a backslash in front of them, which is ignored; this lets you use the characters ] and - in the character class, as well as and ! at the beginning. The pattern matches a single character if it is one of the listed characters or falls into one of the listed ranges (inclusive, case sensitive). Ranges with the first character larger than the second are legal but never match. Edge cases: [] never matches, and [^] and [!] always match without consuming a character.


directory or file or pattern : required, full path of files or directories to be removed.
recursive: optional, true or false.
error: optional, a variable to store error info.


Returns nothing.


Note: In the followings examples, the _ between the { should be removed to make it work.

                void mkdir(owner:"rwx",group:"rwx",other:"x","/tmp/test_remove");
                void generate(file:"/tmp/test_remove/",template:"/tests/");
                void generate(file:"/tmp/test_remove/",template:"/tests/");
                void generate(file:"/tmp/test_remove/gen2.txt",template:"/tests/");
                -e "/tmp/test_remove/gen2.txt";
                -e "/tmp/test_remove/";
        }}. return res=falsetrue.

                void mkdir(owner:"rwx",group:"rwx",other:"x","/tmp/test_remove/other");
                void generate(file:"/tmp/test_remove/other/gen2.txt",template:"/tests/");
                remove(error:t,"/tmp/test_remove/*"); t.errcode;
                -e "/tmp/test_remove/gen2.txt";
                -e "/tmp/test_remove/other";
                remove(recursive:true,error:r,"/tmp/test_remove/*"); r.errcode;
                -e "/tmp/test_remove/other";
        }}. return res=16falsetrue0false.


{{ include("includes/") }}


Written by Pierre Laplante and Caroline Laplante, <>


1.0 2014-09-09 21:24:14


© 2023 extenso Inc. All rights reserved.