Expand description
Crate to help with simple file / folder operations.
Provides helper functions to:
- Create directories
- Check filepaths contain a pattern
- List files / directories both iteratively and recursively
- List files / directories both iteratively and recursively with filters
- Generate names for files / directories
§Async vs Sync
The operations in this crate are designed for async/await, however sync variations
of the operations exist in the crate::sync
module.
§Example
use filetools::{FtFilter, list_nested_files_with_filter};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Get all Lua files in the Neovim directory
let root_path = "/home/user/.config/nvim";
let filter = FtFilter::Raw("lua".to_string());
let lua_files = list_nested_files_with_filter(&root_path, filter).await?;
// Delete them all, we hate Lua
for lua_file in lua_files.into_iter() {
tokio::fs::remove_file(lua_file).await?;
}
Ok(())
}
Modules§
Enums§
- FtFilter
- Filter types for listing files / directories
Functions§
- create_
multiple_ directories - Creates multiple directories inside the target path.
- create_
numeric_ directories - Creates a range of numeric folders in the given path
- ensure_
directory - Creates a directory at the given path.
- is_
subdir - Checks if a given pattern is considered a subdirectory of the given path
- list_
directories - Lists all directories in the given directory (not including subdirectories).
- list_
directories_ with_ filter - Lists directories in a given directory (not including subdirectories) matching a filter pattern.
- list_
files - Lists all files in the given directory (not including subdirectories).
- list_
files_ with_ filter - Lists files in a folder (not including subdirectories) matching a filter pattern.
- list_
nested_ directories - Lists all directories in a directory including ALL subdirectories
- list_
nested_ directories_ with_ filter - Lists directories in a given directory (including ALL subdirectories) matching a filter pattern.
- list_
nested_ files - Lists all files in a directory including ALL subdirectories
- list_
nested_ files_ with_ filter - Lists files in a folder (including ALL subdirectories) matching a filter pattern.
- path_
contains - Determines if a path contains a given pattern