# clear_directory

Definition: | bool res = clear_directory(string path, bool recurse=true)
Description: | Clears a directory of all files, but retains the directory structure. name: the name of the directory whose files you want to remove. recurse: whether or not to remove files in sub-directories. If false then subdirectories are left completely unaltered. Returns: false (0) on failure, true (1) on success.
pwa/p2js: | Not supported.
Comments: | This never removes any directories, it only ever removes files. It is used to clear a directory structure of all existing files, leaving the structure intact. Unlike some other routines here, any path separators should be appropriate for the operating system, namely backslash ('\\') on Windows and forwardslash ('/') on Linux. If in doubt (not already a result from the top half of the table) pass src/dest through get_proper_path() and/or get_proper_dir() before passing them to this routine. A trailing slash is optional, it makes no difference whether one is present or not. The use of a named parameter when setting recurse is recommended, to make the intent clear and the code easier to read.
Example: |
    if clear_directory("build")=false then
        if file_exists("build") then
            return fatal("Filesystem problem - could not begin a clean build")
        end if
    end if
Implementation: | See builtins\pfile.e (an autoinclude) for details of the actual implementation.
See Also: | remove_directory, delete_file
Technicalia | The Euphoria version of this routine returns the number of files deleted, plus one for every directory visited.