file-operation
A Rust library providing comprehensive utilities for file operations with both sync/async support. Includes operations for copy, delete, move, read and write files. Simplifies file handling in Rust projects with safe and efficient methods for file manipulation and metadata querying.
Installation
To use this crate, you can run cmd:
cargo add file-operation
Use
Write to File
Code
let _ = write_to_file;
Description
Writes the given data ("test".as_bytes()
) to the file specified by FILE_PATH
.
FILE_PATH
- Path to the target file.- Returns - A
Result
indicating success or failure.
Read from File
Code
let res: = read_from_file.unwrap_or_default;
Description
Reads the contents of the file specified by FILE_PATH
.
FILE_PATH
- Path to the target file.- Returns - A
Vec<u8>
containing the file content or an empty vector on failure.
Get File Size
Code
let size: = get_file_size;
Description
Retrieves the size of the file specified by FILE_PATH
.
FILE_PATH
- Path to the target file.- Returns - An
Option<u64>
containing the file size in bytes orNone
if the file does not exist.
Copy Directory Files
Code
let res: = copy_dir_files;
Description
Copies all files from FILE_DIR
to NEW_FILE_DIR
.
FILE_DIR
- Source directory path.NEW_FILE_DIR
- Destination directory path.- Returns - A
Result
indicating success or failure.
Delete File
Code
let res: = delete_file;
Description
Deletes the file specified by FILE_PATH
.
FILE_PATH
- Path to the target file.- Returns - A
Result
indicating success or failure.
Move Directory
Code
let res: = move_dir;
Description
Moves the directory specified by FILE_DIR
to NEW_TEST_DIR
.
FILE_DIR
- Source directory path.NEW_TEST_DIR
- Destination directory path.- Returns - A
Result
indicating success or failure.
Delete Directory
Code
let res: = delete_dir;
Description
Deletes the directory specified by NEW_TEST_DIR
.
NEW_TEST_DIR
- Path to the target directory.- Returns - A
Result
indicating success or failure.
Asynchronous Write to File
Code
let _ = async_write_to_file.await;
Description
Writes the given data ("test".as_bytes()
) to the file specified by FILE_PATH
asynchronously.
FILE_PATH
- Path to the target file.- Returns - A
Result
indicating success or failure.
Asynchronous Read from File
Code
let res: = async_read_from_file.await.unwrap_or_default;
Description
Reads the contents of the file specified by FILE_PATH
asynchronously.
FILE_PATH
- Path to the target file.- Returns - A
Vec<u8>
containing the file content or an empty vector on failure.
Asynchronous Get File Size
Code
let size: = async_get_file_size.await;
Description
Retrieves the size of the file specified by FILE_PATH
asynchronously.
FILE_PATH
- Path to the target file.- Returns - An
Option<u64>
containing the file size in bytes orNone
if the file does not exist.
Asynchronous Copy Directory Files
Code
let res: = async_copy_dir_files.await;
Description
Copies all files from FILE_DIR
to NEW_FILE_DIR
asynchronously.
FILE_DIR
- Source directory path.NEW_FILE_DIR
- Destination directory path.- Returns - A
Result
indicating success or failure.
Asynchronous Delete File
Code
let res: = async_delete_file.await;
Description
Deletes the file specified by FILE_PATH
asynchronously.
FILE_PATH
- Path to the target file.- Returns - A
Result
indicating success or failure.
Asynchronous Move Directory
Code
let res: = async_move_dir.await;
Description
Moves the directory specified by FILE_DIR
to NEW_TEST_DIR
asynchronously.
FILE_DIR
- Source directory path.NEW_TEST_DIR
- Destination directory path.- Returns - A
Result
indicating success or failure.
Asynchronous Delete Directory
Code
let res: = async_delete_dir.await;
Description
Deletes the directory specified by NEW_TEST_DIR
asynchronously.
NEW_TEST_DIR
- Path to the target directory.- Returns - A
Result
indicating success or failure.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Contact
For any inquiries, please reach out to the author at root@ltpp.vip.