-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b83b440
Showing
6 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "justatry" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#[allow(unused_imports)] | ||
use std::fs::{self, File}; | ||
use std::io::{self}; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
loop { | ||
println!("Enter a command (list, create, delete, exit):"); | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).expect("Failed to read line"); | ||
let command = input.trim(); | ||
|
||
match command { | ||
"list" => { | ||
println!("Enter the directory path:"); | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).expect("Failed to read line"); | ||
let path = input.trim(); | ||
let dir = Path::new(path); | ||
if dir.is_dir() { | ||
for entry in fs::read_dir(dir).expect("Failed to read directory") { | ||
if let Ok(entry) = entry { | ||
println!("{}", entry.path().display()); | ||
} | ||
} | ||
} else { | ||
println!("{} is not a directory", path); | ||
} | ||
} | ||
"create" => { | ||
println!("Enter the file path:"); | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).expect("Failed to read line"); | ||
let path = input.trim(); | ||
File::create(path).expect("Failed to create file"); | ||
println!("Created file {}", path); | ||
} | ||
"delete" => { | ||
println!("Enter the file path:"); | ||
let mut input = String::new(); | ||
io::stdin().read_line(&mut input).expect("Failed to read line"); | ||
let path = input.trim(); | ||
fs::remove_file(path).expect("Failed to delete file"); | ||
println!("Deleted file {}", path); | ||
} | ||
"exit" => { | ||
println!("Exiting..."); | ||
break; | ||
} | ||
_ => { | ||
println!("Invalid command"); | ||
} | ||
} | ||
} | ||
} |