Crates.io | wildpath |
lib.rs | wildpath |
version | 0.1.0 |
source | src |
created_at | 2024-03-27 02:31:33.744245 |
updated_at | 2024-03-27 02:31:33.744245 |
description | A library to find all filepaths that fit a given pattern |
homepage | https://github.com/Matyasz/wildpath |
repository | https://github.com/Matyasz/wildpath |
max_upload_size | |
id | 1187464 |
size | 16,072 |
A rust library to resolve wildcards in filepaths on UNIX systems.
The library exposes one method, resolve
, which will take a filepath with wildcards and return everything on the filesystem that fits the given description.
For example, consider a file system that looks like the following:
root
├── blogs
│ ├── blog_1
│ │ ├── assets
│ │ │ └── logo.jpeg
│ │ └── post.txt
│ └── blog_2
│ ├── assets
│ │ └── research_notes.txt
│ └── post.txt
└── videos
├── video_1
│ ├── assets
│ │ └── logo.jpeg
│ └── script.txt
├── video_2
│ ├── assets
│ │ └── sound_effect.wav
│ └── script.txt
└── video_3
├── assets
│ └── new_logo.png
└── script.txt
If you want to find all of the text for the content, you can call
resolve(&Path::new("/root/*/*/*.txt").unwrap())
which will return all of the txt
files that are 3 layers deep:
[
"/root/blogs/blog_1/post.txt",
"/root/blogs/blog_2/post.txt",
"/root/videos/video_1/script.txt",
"/root/videos/video_2/script.txt",
"/root/videos/video_3/script.txt"
]
If you want to see all of the versions of logos that have been used, you can call
resolve(&Path::new("/root/*/*/assets/*logo*").unwrap())
which will return
[
"/root/blogs/blog_1/assets/logo.jpeg",
"/root/videos/video_1/assets/logo.jpeg",
"/root/videos/video_3/assets/new_logo.png"
]
Or if you want to see the logos used for the original blog and video, you can call
resolve(&Path::new("/root/*/*_1/assets/*logo*").unwrap())
which will return
[
"/root/blogs/blog_1/assets/logo.jpeg",
"/root/videos/video_1/assets/logo.jpeg"
]
and if you add a new directory called presentations
, as long as it follows the same structure as the others, this same line of code will also pick up the logo used in the first presentation.
wildpath
will also follow symlinks and resolve. For example, if you have the following filesystem:
root
├── A
│ └── X (<- symlink to B)
└── B
└── c.png
and pass a path of /root/A/*/*
, you will receive [/root/B/c.png]
as the output.
wildpath
has only been tested on a UNIX system. For now, it may not work on Windows..
or ..
in a path. For now, these will need to be resolved prior to using the library.