1use std::path::Path;
5pub use std::{
6 fs::{
7 create_dir, read_dir, read_to_string, remove_dir_all, remove_file, write as std_write,
8 read as std_read, canonicalize, metadata, Metadata,
9 },
10 io::Result,
11};
12
13pub fn fstat<P>(path: P) -> Result<Metadata>
18where
19 P: AsRef<Path>,
20{
21 metadata(path)
22}
23
24pub fn mkdir<P>(path: P) -> Result<()>
29where
30 P: AsRef<Path>,
31{
32 if read_dir(&path).is_err() {
33 create_dir(path)?
34 }
35
36 Ok(())
37}
38
39pub fn rmdirr<P: AsRef<Path>>(path: P) -> Result<()>
44where
45 P: AsRef<Path>,
46{
47 if read_dir(&path).is_err() {
48 return Ok(()); }
50
51 remove_dir_all(path)
52}
53
54pub fn rm<P: AsRef<Path>>(path: P) -> Result<()>
59where
60 P: AsRef<Path>,
61{
62 remove_file(path)
63}
64
65pub fn write<P, D>(path: P, data: D) -> Result<()>
71where
72 P: AsRef<Path>,
73 D: AsRef<[u8]>,
74{
75 std_write(path, data)
76}
77
78pub fn touch<P>(path: P) -> Result<()>
83where
84 P: AsRef<Path>,
85{
86 std_write(path, "")
87}
88
89pub fn append<P, D>(path: P, data: D) -> Result<()>
95where
96 P: AsRef<Path>,
97 D: AsRef<[u8]>,
98{
99 let mut bytes = std_read(&path)?; bytes = [&bytes, data.as_ref()].concat(); std_write(path, bytes) }
103
104pub fn read<P: AsRef<Path>>(path: P) -> Result<String>
112where
113 P: AsRef<Path>,
114{
115 read_to_string(path)
116}