[#BloombergLP-bdls-FilesystemUtil-remove-07]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdls.adoc[bdls]::xref:BloombergLP/bdls/FilesystemUtil.adoc[FilesystemUtil]::remove
:relfileprefix: ../../../
:mrdocs:

Remove the file or directory at the specified `path`&period;

== Synopsis

Declared in `&lt;bdls&lowbar;filesystemutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
remove(
    char const* path,
    bool recursiveFlag = false);
----

== Description

If the `path` refers to a directory and the optionally specified `recursiveFlag` is `true`, recursively remove all files and directories within the specified directory before removing the directory itself&period; Return 0 on success and a non&hyphen;zero value otherwise&period; If `path` refers to a symbolic link, the symbolic link will be removed, not the target of the link&period; Note that if `path` is a directory, and the directory is not empty, and recursive is `false`, this method will fail&period; Also note that if the function fails when `recursive` is `true`, it may or may not have removed _some_ files or directories before failing&period; Also note that if `remove` is called on &quot;&period;&quot; or &quot;&period;&period;&quot;, it will fail with no effect&period; The parameterized `STRING&lowbar;TYPE` must be one of `bsl&colon;&colon;string`, `std&colon;&colon;string`, `std&colon;&colon;pmr&colon;&colon;string` (if supported), `bsl&colon;&colon;string&lowbar;view`, or `bslstl&colon;&colon;StringRef`&period;

WINDOWS&hyphen;SPECIFIC WARNING&colon; When `recursiveFlag` is `true`, it is possible for this function to descend into a directory symbolic link, resulting in the removal of files or directories that are outside the subtree of `path`&period; This situation occurs only if a directory is replaced by a symbolic link during the traversal&period; Note that when Developer Mode is not enabled, symbolic links can be created only by users with administrative privileges&period; If Developer Mode is on, using this function for recursive deletion can result in a vulnerability similar to https://nvd.nist.gov/vuln/detail/cve-2022-21658[CVE&hyphen;2022&hyphen;21658]&period;

== Return Value

0 on success, and a non&hyphen;zero value otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *path*
| filesystem path of the file or directory to remove
| *recursiveFlag*
| whether to recursively remove directory contents
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
