https://github.com/feenkcom/file-matcher-rs
A Rust library to search files based on the name pattern (regex, wildcard, exact).
https://github.com/feenkcom/file-matcher-rs
Last synced: about 1 year ago
JSON representation
A Rust library to search files based on the name pattern (regex, wildcard, exact).
- Host: GitHub
- URL: https://github.com/feenkcom/file-matcher-rs
- Owner: feenkcom
- License: mit
- Created: 2021-07-16T13:13:51.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-13T05:49:17.000Z (over 4 years ago)
- Last Synced: 2025-04-11T05:07:01.778Z (about 1 year ago)
- Language: Rust
- Size: 39.1 KB
- Stars: 7
- Watchers: 10
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# file-matcher
[](https://docs.rs/file-matcher)
[](https://crates.io/crates/file-matcher)
[](https://opensource.org/licenses/MIT)
A Rust library to search files and folders based on the name pattern (regex, wildcard, exact).
### Features
* `regex` - adds regex support using [Regex crate](https://crates.io/crates/regex)
* `wildmatch` - adds a wildcard matching using [Wildmatch crate](https://crates.io/crates/wildmatch)
* `copier` - allows users to copy declared files and folders, uses [fs_extra crate](https://crates.io/crates/fs_extra)
* `mover` - allows users to move declared files and folders, uses [fs_extra crate](https://crates.io/crates/fs_extra)
* `serde` - allows users to serialize / deserialize declared file and folder filters, uses [serde](https://crates.io/crates/serde)
### Search
Use `FileNamed` to search for exactly one file matching the name pattern. Returns an `Error` if none or more than one file was found.
```rust
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.
```rust
FolderNamed::wildmatch("cat*")
.within("tests/assets")
.find()?
```
### Existence
Check if a file exists:
```rust
FileNamed::wildmatch("cat*")
.within("tests/assets")
.exists()?
```
Check if a folder exists:
```rust
FolderNamed::wildmatch("cat*")
.within("tests/assets")
.exists()?
```
### Copy
Find and copy a file matching a name pattern to `destination` folder under the same name:
```rust
FileNamed::wildmatch("cat*")
.within("tests/assets")
.copy("destination")?
```
Find and copy a file matching a name pattern to `destination` folder as `kitty.txt`:
```rust
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:
```rust
FileNamed::wildmatch("cat*")
.alias("kitty.txt")
.within("tests/assets")
.copy("destination")?
```