unpack_and_move.pl: use strict, make script crossplatform, use builtin move file operation.
This commit is contained in:
@@ -2,18 +2,36 @@
|
||||
|
||||
# finds in current dir 7z compressed file, makes dir according filename,
|
||||
# move file to that dir, unpack file to that dir, remove file
|
||||
use warnings "all";
|
||||
use strict;
|
||||
|
||||
use File::Copy;
|
||||
|
||||
my $sevenzip = '7z';
|
||||
|
||||
if ($^O =~ /MSWin32/) {
|
||||
if (-f "$ENV{'ProgramFiles'}/7-Zip/7z.exe") {
|
||||
$sevenzip = "$ENV{'ProgramFiles'}/7-Zip/7z.exe";
|
||||
} elsif (-f "$ENV{'ProgramFiles(x86)'}/7-Zip/7z.exe") {
|
||||
$sevenzip = "$ENV{'ProgramFiles(x86)'}/7-Zip/7z.exe";
|
||||
} else {
|
||||
print "no 7-zip found in program files\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
opendir(S, ".");
|
||||
@list = readdir(S);
|
||||
my @list = readdir(S);
|
||||
|
||||
foreach (@list) {
|
||||
next if ($_ eq ".");
|
||||
next if($_ eq "..");
|
||||
$filename = $_;
|
||||
$name = (split(/\.7z/, $filename))[0];
|
||||
my $filename = $_;
|
||||
my $name = (split(/\.7z/, $filename))[0];
|
||||
next unless (mkdir($name));
|
||||
system("mv", $filename, $name);
|
||||
next unless ( move ($filename, $name) == 1);
|
||||
next unless (chdir($name));
|
||||
system("7z", "x", $filename);
|
||||
system($sevenzip, "x", $filename);
|
||||
unlink($filename);
|
||||
chdir("..");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user