Advertisement
leo1553

Unrar All

Mar 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5.  
  6. namespace UnrarAll {
  7.     class Program {
  8.         const string Exec = @"C:\Program Files\7-Zip\7z.exe";
  9.         const string Params = "e \"{0}\" -o\"{1}\" -r";
  10.         const string initialPath = @"C:\Users\Leonardo Leal\Desktop\Puzzle\puzzle.tar.gz";
  11.         static void Main(string[] args) {
  12.             List<string> toDo = new List<string>() {
  13.                 initialPath
  14.             };
  15.  
  16.             List<string> files = new List<string>();
  17.  
  18.             int count = 0;
  19.             while(toDo.Count != 0) {
  20.                 string path = string.Format(@"{0}{1}\", AppDomain.CurrentDomain.BaseDirectory, count++);
  21.                 Directory.CreateDirectory(path);
  22.                
  23.                 Process process = Process.Start(Exec, string.Format(Params, toDo[0], path));
  24.                 process.WaitForExit();
  25.  
  26.                 foreach(string file in Directory.GetFiles(path)) {
  27.                     string ext = Path.GetExtension(file);
  28.                     switch(ext) {
  29.                         case ".rar":
  30.                         case ".zip":
  31.                         case ".jar":
  32.                         case ".tar":
  33.                         case ".gz":
  34.                         case ".tar.gz":
  35.                         case ".7z":
  36.                             toDo.Add(file);
  37.                             break;
  38.                         default:
  39.                             files.Add(file);
  40.                             break;
  41.                     }
  42.                 }
  43.  
  44.                 toDo.RemoveAt(0);
  45.             }
  46.  
  47.             Console.WriteLine("Done unzipping {0} files", count);
  48.             Console.WriteLine("Files found:");
  49.             Console.WriteLine(string.Join("\n", files));
  50.             Console.ReadLine();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement