qfile-2.2.2 has been yanked.
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
// add_path() - constructor for adding a file path.
// the real file path: `./FOLDER/folder/File.txt`
let mut file = add_path.unwrap;
// after using auto_write() 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.auto_write.unwrap;
// we get the saved path from the cache
file.auto_write.unwrap;
assert_eq!;
use Error;
use *;
use *;
use BufReader;
use Read;
// The file already exists
// The real file path: "./My_First_Folder/New_File.txt"
// File content: Hello World
let file = add_path
.unwrap
.get_file
.unwrap;
let mut buffer = Vecnew;
// Read file into vector.
new.read_to_end.unwrap;
// Show result
assert_eq!
Paths syntax
Linux
folder/folder/file.txt
./folder/folder/file.txt
let path1 = "File.txt";
let path2 = "./File.txt";
let path3 = "../../File.txt";
let path4 = Stringfrom;
Windows
folder\\folder\\file.txt
.\\folder\\folder\\file.txt
D:\\folder\\folder\\file.txt
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 = Stringfrom;
Auto mode
Creates or opens if a file exists (case insensitive)
Example
let mut file = add_path.unwrap;
file.auto_write.unwrap;
//=========
//*code*
//=========
file.auto_write.unwrap;
assert_eq;
Linux & Windows
- If the path exists, we work with the file (case insensitive)
| Linux | Windows | |
|---|---|---|
| The path we specified: | folder1/FolDER2/file.TXT |
folder1\FolDER2\file.TXT |
| Real path : | ./Folder1/Folder2/file.txt |
.\Folder1\Folder2\file.txt |
| Result : | ./Folder1/Folder2/file.txt |
.\Folder1\Folder2\file.txt |
- If the file/path is not found, creates a new path with the file
| Linux | Windows | |
|---|---|---|
| The path we specified: | ./main_folder/folder_new/file.txt |
.\main_folder\folder_new\file.txt |
| Real path : | ./Main_Folder |
.\Main_Folder |
| Result : | ./Main_Folder/folder_new/file.txt |
.\Main_Folder\folder_new\file.txt |
- The Windows file system treats file and directory names as case insensitive.
file.txtandFILE.txtwill be treated as equivalent files (Although the path is case insensitive in windows (..\FOLDER\file.txt), you can return a case-sensitive path with :get_path_str()orget_path_buf()).