|
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Support for matching file paths against Unix shell style patterns."><title>glob - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="glob" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../glob/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../glob/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" alt="logo"></a><h2><a href="../glob/index.html">glob</a><span class="version">0.3.1</span></h2></div><div class="sidebar-elems"><ul class="block">
|
|
|
<li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Aliases</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
|
|
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../glob/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">glob</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/glob/lib.rs.html#11-1434">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Support for matching file paths against Unix shell style patterns.</p>
|
|
|
<p>The <code>glob</code> and <code>glob_with</code> functions allow querying the filesystem for all
|
|
|
files that match a particular pattern (similar to the libc <code>glob</code> function).
|
|
|
The methods on the <code>Pattern</code> type provide functionality for checking if
|
|
|
individual paths match a particular pattern (similar to the libc <code>fnmatch</code>
|
|
|
function).</p>
|
|
|
<p>For consistency across platforms, and for Windows support, this module
|
|
|
is implemented entirely in Rust rather than deferring to the libc
|
|
|
<code>glob</code>/<code>fnmatch</code> functions.</p>
|
|
|
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
|
|
<p>To print all jpg files in <code>/media/</code> and all of its subdirectories.</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>glob::glob;
|
|
|
|
|
|
<span class="kw">for </span>entry <span class="kw">in </span>glob(<span class="string">"/media/**/*.jpg"</span>).expect(<span class="string">"Failed to read glob pattern"</span>) {
|
|
|
<span class="kw">match </span>entry {
|
|
|
<span class="prelude-val">Ok</span>(path) => <span class="macro">println!</span>(<span class="string">"{:?}"</span>, path.display()),
|
|
|
<span class="prelude-val">Err</span>(e) => <span class="macro">println!</span>(<span class="string">"{:?}"</span>, e),
|
|
|
}
|
|
|
}</code></pre></div>
|
|
|
<p>To print all files containing the letter “a”, case insensitive, in a <code>local</code>
|
|
|
directory relative to the current working directory. This ignores errors
|
|
|
instead of printing them.</p>
|
|
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>glob::glob_with;
|
|
|
<span class="kw">use </span>glob::MatchOptions;
|
|
|
|
|
|
<span class="kw">let </span>options = MatchOptions {
|
|
|
case_sensitive: <span class="bool-val">false</span>,
|
|
|
require_literal_separator: <span class="bool-val">false</span>,
|
|
|
require_literal_leading_dot: <span class="bool-val">false</span>,
|
|
|
};
|
|
|
<span class="kw">for </span>entry <span class="kw">in </span>glob_with(<span class="string">"local/*a*"</span>, options).unwrap() {
|
|
|
<span class="kw">if let </span><span class="prelude-val">Ok</span>(path) = entry {
|
|
|
<span class="macro">println!</span>(<span class="string">"{:?}"</span>, path.display())
|
|
|
}
|
|
|
}</code></pre></div>
|
|
|
</div></details><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.GlobError.html" title="struct glob::GlobError">GlobError</a></div><div class="desc docblock-short">A glob iteration error.</div></li><li><div class="item-name"><a class="struct" href="struct.MatchOptions.html" title="struct glob::MatchOptions">MatchOptions</a></div><div class="desc docblock-short">Configuration options to modify the behaviour of <code>Pattern::matches_with(..)</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.Paths.html" title="struct glob::Paths">Paths</a></div><div class="desc docblock-short">An iterator that yields <code>Path</code>s from the filesystem that match a particular
|
|
|
pattern.</div></li><li><div class="item-name"><a class="struct" href="struct.Pattern.html" title="struct glob::Pattern">Pattern</a></div><div class="desc docblock-short">A compiled Unix shell style pattern.</div></li><li><div class="item-name"><a class="struct" href="struct.PatternError.html" title="struct glob::PatternError">PatternError</a></div><div class="desc docblock-short">A pattern parsing error.</div></li></ul><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.glob.html" title="fn glob::glob">glob</a></div><div class="desc docblock-short">Return an iterator that produces all the <code>Path</code>s that match the given
|
|
|
pattern using default match options, which may be absolute or relative to
|
|
|
the current working directory.</div></li><li><div class="item-name"><a class="fn" href="fn.glob_with.html" title="fn glob::glob_with">glob_with</a></div><div class="desc docblock-short">Return an iterator that produces all the <code>Path</code>s that match the given
|
|
|
pattern using the specified match options, which may be absolute or relative
|
|
|
to the current working directory.</div></li></ul><h2 id="types" class="section-header"><a href="#types">Type Aliases</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.GlobResult.html" title="type glob::GlobResult">GlobResult</a></div><div class="desc docblock-short">An alias for a glob iteration result.</div></li></ul></section></div></main></body></html> |