Crate Docs Changelog

# Qfile

Crate for accessing a file by path, case insensitive. Automatic detection, create a path with a new file or open an existing file.

# Examples ``rust // add_path() - constructor for adding a file path. // the real file path:./FOLDER/folder/File.txt` let mut file = QFilePath::addpath("./folder/folder/file.txt").unwrap(); // after using autowrite() or read() methods, and if Ok(), // we get/save the correct path after the first method call, // which will be used as a cache when used again. file.autowrite("text1").unwrap(); // we get the saved path from the cache file.autowrite("text2").unwrap(); asserteq!(file.read().unwrap(), "text1text_2");

```


rust use std::error::Error; use qfile::*; fn create_files(count: i32) -> Result<(), Box<dyn Error>> { for i in 0..=count { QFilePath::add_path(format!("FolderPack/file-{}.txt", i))?.auto_write("")?; } Ok(()) } fn main() { create_files(100).unwrap(); }


rust use qfile::*; use std::io::BufReader; use std::io::Read; // The file already exists // The real file path: "./My_First_Folder/New_File.txt" // File content: Hello World let file = QFilePath::add_path("my_first_Folder/new_file.txt") .unwrap() .get_file(Permissions::RW) .unwrap(); let mut buffer = Vec::new(); // Read file into vector. BufReader::new(file).read_to_end(&mut buffer).unwrap(); // Show result assert_eq!( buffer, vec![72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100] )


Paths syntax

Linux

folder/folder/file.txt\ ./folder/folder/file.txt

rust let path1 = "File.txt"; let path2 = "./File.txt"; let path3 = "../../File.txt"; let path4 = String::from("Folder/Folder/File.txt");

Windows

folder\\folder\\file.txt\ .\\folder\\folder\\file.txt\ D:\\folder\\folder\\file.txt

rust let path1 = "File.txt"; let path2 = ".\\File.txt"; let path3 = "..\\..\\File.txt"; let path4 = "D:\\Folder\\file.txt"; let path5 = r"D:\Folder\file.txt"; let path6 = String::from("D:\\Folder\\file.txt");

Auto mode

Creates or opens if a file exists (case insensitive)

Example

```rust let mut file = QFilePath::addpath("./file.txt").unwrap(); file.autowrite("ok").unwrap(); //========= //code //========= file.autowrite("ok").unwrap(); asserteq(file.read().unwrap(),"okok");

```

Linux & Windows


# Changelog List # License MIT