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

Recursively traverse the directory tree starting at the specified `root` for files whose leaf names match the specified `pattern`, and run the specified function `visitor`, passing it the full path starting with `root` to each pattern matching file&period; See `findMatchingPaths` for a discussion of how `pattern` is interpreted&period; If the specified `sortFlag` is `true`, traverse the files in the tree in sorted order, sorted by the full path name, otherwise the order in which the files will be visited is unspecified&period; UTF&hyphen;8 paths will be sorted by `strcmp`, which sorts by `char`s, not unicode code points&period; Found `&period;` and `&period;&period;` directories are ignored, except that `root` may be `&period;` or `&period;&period;`&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; This function will fail if `root` does not specify a directory, of if `pattern` contains `&sol;` on Unix or &apos;&apos; on Windows&period; Note that both directories and plain files whose names match `pattern` will be visited, while other files such as symlinks will not be visited or followed&period; No file or directory that is not matched will be visited&period; All directories are traversed, regardless of whether they are matched&period; If a directory is matched and `sortFlag` is `true`, it is visited immediately before it is traversed&period; Also note that `root` is never visited, even if it matches `pattern`&period; Also note that no pattern matching is done on `root` &hyphen;&hyphen; if it contains wildcards, they are not interpreted as such and must exactly match the characters in the name of the directory&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
visitTree(
    std::string&lowbar;view const& root,
    std::string&lowbar;view const& pattern,
    xref:bsl/function-0a.adoc[bsl::function&lt;void(char const*)&gt;] const& visitor,
    bool sortFlag = false);
----

== Description

IBM&hyphen;SPECIFIC WARNING&colon; This function is not thread&hyphen;safe&period; The AIX implementation of the system `glob` function can temporarily change the working directory of the entire program, casuing attempts in other threads to open files with relative path names to fail&period;


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