Advertisement
Guest User

archive checker

a guest
Jul 11th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.83 KB | None | 0 0
  1. # testarchives.pl
  2. #
  3. # Tests all the archives of the matching filetypes in the current directory and subdirectories.
  4. # The results are saved in a text file named "corrupt.txt".
  5. # If there is a directory named "corrupt" in the current directory, archives with errors will be moved to it.
  6. #
  7. # You are free to modify and distribute this file
  8. # (C)'2010 malor89
  9. #
  10. # last modified: 11/21/10
  11. #
  12. ##########################################################################
  13.  
  14. $sevenzip = "C:\\Program Files\\7-Zip\\7z.exe";  #path to 7z.exe from 7-zip program, make sure to use \\ and not single \ in path
  15. $filetypes = "cbr|cbz|cb7";  #filetypes to test, use | between types
  16. $skipdir = "System Volume Information|$RECYCLE.BIN|corrupt";   #don't scan these directories, use | between names
  17. my $logfile = "corrupt.txt";
  18.  
  19. listdir(".");
  20. printf ("%-79s\n", " ");
  21. print "\n--- Done ---\n";
  22. sleep(600);
  23. exit;
  24.  
  25. sub listdir{
  26.     my ($dir) = @_;
  27.     my ($file, @files, @list);
  28.     opendir(DIR, $dir) || return;
  29.     @files = grep { /^[^.]/} readdir(DIR);
  30.     closedir DIR;
  31.  
  32.     foreach $file(sort(@files)) {
  33.         if (-d "$dir\\$file") {
  34.             if (! ($file =~/^$skipdir$/i)) {
  35.                 listdir("$dir\\$file");
  36.             }
  37.         } elsif ($file =~ /\.($filetypes)$/i) {
  38.             open (DATA, "\"$sevenzip\" t \"$dir\\$file\"|");
  39.             @list = <DATA>;
  40.             close(DATA);
  41.             $info = $list[$#list-1];
  42.             if ($info =~ /Sub items Errors: (\d+)/) {
  43.                 if ($1 == 1) {
  44.                     printf ("%-79s\n", substr($file,0,70).": $1 Error");
  45.                 } else {
  46.                     printf ("%-79s\n", substr($file,0,69).": $1 Errors");
  47.                 }
  48.                 open(my $log, '>>', $logfile) or die "Could not open file '$filename' $!";
  49.                 print $log "$dir\\$file\t$1\n";
  50.                 close $log;
  51.                 if(not (-e "corrupt\\$file")) {
  52.                     rename  ("$dir\\$file", "corrupt\\$file");
  53.                 }
  54.             } else {
  55.                 printf ("%-79s\r", substr($file,0,75).": OK");
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement