Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
its-me-ojas committed Oct 4, 2023
0 parents commit b83b440
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
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 added src/main.exe
Binary file not shown.
Binary file added src/main.pdb
Binary file not shown.
55 changes: 55 additions & 0 deletions src/main.rs
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");
}
}
}
}

0 comments on commit b83b440

Please sign in to comment.