Module file

Source
Expand description

This module provides advanced functions for file and directory operations.

It offers a simple and efficient way to work with files and directories, allowing you to create, read, update, delete, list, copy, move, and rename files with ease.

§Features

  • CRUD operations on files
  • Listing directory contents
  • Copying, moving, and renaming files
  • Error handling with custom error types
  • All operations use only the Rust standard library

§Examples

use dev_utils::file::*;

// Create a new file
let file_path = create("test.txt", "Hello, World!").unwrap();

// Read the file contents
let content = read(&file_path).unwrap();
assert_eq!(content, "Hello, World!");

// Update the file contents
update(&file_path, "Updated content").unwrap();
assert_eq!(read(&file_path).unwrap(), "Updated content");

// Append to the file
append(&file_path, " Appended content").unwrap();
assert_eq!(read(&file_path).unwrap(), "Updated content Appended content");

// Delete the file
delete(&file_path).unwrap();
assert!(!file_path.exists());

Enums§

FileError
Custom error type for file operations.

Functions§

append
Appends content to the end of a file.
copy
Copies a file from one location to another.
create
Creates a new file with the given content.
delete
Deletes a file.
find
Finds files in a directory (and its subdirectories) that match a given predicate.
list
Lists the contents of a directory.
mv
Moves a file from one location to another.
read
Reads the contents of a file.
recursive_copy
Recursively copies a directory and its contents.
rename
Renames a file.
update
Updates the contents of a file.