Crate filetools

Source
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§

naming
Functions that generate PathBuf filenames
sync
Sync variations of the main crate functions

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