Add not builtin command - touch

This commit is contained in:
g1n 2021-07-22 07:19:29 +00:00
parent 3f0160f2f6
commit b77a44a031
1 changed files with 21 additions and 0 deletions

21
src/touch.rs Normal file
View File

@ -0,0 +1,21 @@
use std::env;
use std::fs::{self, File};
use std::path::Path;
fn main(){
let args: Vec<String> = env::args().collect();
for arg in 1..args.len() {
match args[arg].as_str() {
"--help" => {
println!("Usage: touch [OPTIONS] FILE");
println!("Creates empty file");
return;
},
arg => {
if !Path::new(arg).exists() {
File::create(arg);
}
}
}
}
}