Johann Woelper 4 anni fa
parent
commit
3d483d71d7
1 ha cambiato i file con 17 aggiunte e 2 eliminazioni
  1. 17 2
      src/main.rs

+ 17 - 2
src/main.rs

@@ -14,6 +14,12 @@ fn main() {
          .help("Only extract file containing this string")
          .takes_value(true)
         )
+    .arg(Arg::with_name("rename")
+        //  .short("rn")
+         .long("rename")
+         .help("Rename EVERY file to this string. Useful in scripts with the random option")
+         .takes_value(true)
+        )
     .arg(Arg::with_name("ignorepath")
          .short("i")
          .long("ignorepath")
@@ -34,6 +40,7 @@ fn main() {
 
     let archive = matches.value_of("ZIP").unwrap();
     let filter = matches.value_of("filter");
+    let rename = matches.value_of("rename");
     let do_ignorepath = matches.is_present("ignorepath");
     let do_random = matches.is_present("random");
 
@@ -84,15 +91,23 @@ fn main() {
         }
 
         if (&*file.name()).ends_with('/') {
-            println!("File {} extracted to \"{}\"", i, outpath.as_path().display());
+            // println!("File {} extracted to \"{}\"", i, outpath.as_path().display());
                 fs::create_dir_all(&outpath).unwrap();
         } else {
-            println!("File {} extracted to \"{}\" ({} bytes)", i, outpath.as_path().display(), file.size());
+            // println!("File {} extracted to \"{}\" ({} bytes)", i, outpath.as_path().display(), file.size());
             if let Some(p) = outpath.parent() {
                 if !p.exists() {
                     fs::create_dir_all(&p).unwrap();
                 }
             }
+            
+            if let Some(r) = rename {
+                outpath = PathBuf::from(r);
+            }
+
+            println!("{}", outpath.as_path().display());
+
+
             let mut outfile = fs::File::create(&outpath).unwrap();
             io::copy(&mut file, &mut outfile).unwrap();
         }