#pattern-matching #file #file-search #folders #regex #filename

file-matcher

A library to search files and folders based on the name pattern (regex, wildmatch, exact)

6 releases (breaking)

0.7.0 Oct 12, 2021
0.6.0 Aug 3, 2021
0.5.0 Jul 23, 2021
0.4.0 Jul 20, 2021
0.2.4 Jul 16, 2021

#1076 in Filesystem

Download history 199/week @ 2024-07-21 165/week @ 2024-07-28 75/week @ 2024-08-04 114/week @ 2024-08-11 122/week @ 2024-08-18 161/week @ 2024-08-25 164/week @ 2024-09-01 100/week @ 2024-09-08 131/week @ 2024-09-15 219/week @ 2024-09-22 368/week @ 2024-09-29 457/week @ 2024-10-06 384/week @ 2024-10-13 158/week @ 2024-10-20 155/week @ 2024-10-27 252/week @ 2024-11-03

968 downloads per month

MIT license

38KB
893 lines

file-matcher

docs crate license

A Rust library to search files and folders based on the name pattern (regex, wildcard, exact).

Features

  • regex - adds regex support using Regex crate
  • wildmatch - adds a wildcard matching using Wildmatch crate
  • copier - allows users to copy declared files and folders, uses fs_extra crate
  • mover - allows users to move declared files and folders, uses fs_extra crate
  • serde - allows users to serialize / deserialize declared file and folder filters, uses serde

Use FileNamed to search for exactly one file matching the name pattern. Returns an Error if none or more than one file was found.

FileNamed::regex("cat.*")
    .within("tests/assets")
    .find()?

Use FolderNamed to search for exactly one folder matching the name pattern. Returns an Error if none or more than one folder was found.

FolderNamed::wildmatch("cat*")
    .within("tests/assets")
    .find()?

Existence

Check if a file exists:

FileNamed::wildmatch("cat*")
    .within("tests/assets")
    .exists()?

Check if a folder exists:

FolderNamed::wildmatch("cat*")
    .within("tests/assets")
    .exists()?

Copy

Find and copy a file matching a name pattern to destination folder under the same name:

FileNamed::wildmatch("cat*")
    .within("tests/assets")
    .copy("destination")?

Find and copy a file matching a name pattern to destination folder as kitty.txt:

FileNamed::wildmatch("cat*")
    .within("tests/assets")
    .copy(Path::new("destination").join("kitty.txt"))?

Alternatively, assign an alias for copy/move operations. The following will find a file matching a given pattern name and will copy it into the destination folder under the kitty.txt name:

FileNamed::wildmatch("cat*")
    .alias("kitty.txt")
    .within("tests/assets")
    .copy("destination")?

Dependencies

~0–710KB
~13K SLoC