How it works...

This crate is pretty small and simple. With glob(...), you can create an iterator over all matching files by specifying a glob pattern. If you aren't familiar with them but remember the regex recipe from earlier (in the Querying with regexes section in Chapter 1Learning the Basics), think of them as very simplified regexes used primarily for filenames. Its syntax is nicely described on Wikipedia: https://en.wikipedia.org/wiki/Glob_(programming).

As with WalkDir before, the glob iterator returns a Result because the program might not have the permissions to read a filesystem entry. Inside the Result sits a Path, which we also touched on in the last recipe. If you want to read the contents of the file, refer to the first recipe in this chapter, which deals with file manipulation.

With glob_with, you can specify a MatchOptions instance to change the way glob searches for files. The most useful options you can toggle are:

  • case_sensitive: This is enabled per default and controls whether lowercase letters (abcd) and uppercase letters (ABCD) should be treated differently or not.
  • require_literal_leading_dot: This is disabled per default and, when set, prohibits wildcards from matching a leading dot in a filename. This is used when you want to ignore a user's hidden files.

You can view the rest of the options in the documentation of MatchOptionhttps://doc.rust-lang.org/glob/glob/struct.MatchOptions.html.

If you have set the options you care about, you can leave the rest at their default by using the ..Default::default() update syntax discussed in the Providing a default implementation section in Chapter 1, Learning the Basics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.105.159