From 7731c177c9e86e01ea77807d6559f734a3ed2c91 Mon Sep 17 00:00:00 2001 From: licsber Date: Sat, 7 Sep 2024 23:53:17 +0800 Subject: [PATCH] init commit. --- .gitignore | 1 + .idea/.gitignore | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/unzip-all.iml | 11 +++++++++++ .idea/vcs.xml | 6 ++++++ Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/unzip-all.iml create mode 100644 .idea/vcs.xml create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f02f262 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/unzip-all.iml b/.idea/unzip-all.iml new file mode 100644 index 0000000..cf84ae4 --- /dev/null +++ b/.idea/unzip-all.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..86caded --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "unzip-all" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c5a87dc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "unzip-all" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..009c6e9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,39 @@ +use std::fs; +use std::io; +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn process_compressed_files(path: &Path) -> io::Result<()> { + if path.is_dir() { + for entry in fs::read_dir(path)? { + let entry_path = entry?.path(); + process_compressed_files(&entry_path)?; + } + } else { + if path.extension() == Some(std::ffi::OsStr::new("rar")) + || path.extension() == Some(std::ffi::OsStr::new("zip")) { + let output = Command::new("unar") + .arg(path) + .output(); + + match output { + Ok(result) => { + if !result.status.success() { + eprintln!("Error processing compressed file {:?}: {}", path, String::from_utf8_lossy(&result.stderr)); + } + } + Err(e) => { + eprintln!("Failed to execute unar for {:?}: {}", path, e); + } + } + } + } + + Ok(()) +} + +fn main() -> io::Result<()> { + let start_path = PathBuf::from("."); + process_compressed_files(&start_path)?; + Ok(()) +}