-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmlist
More file actions
executable file
·53 lines (42 loc) · 1.03 KB
/
rmlist
File metadata and controls
executable file
·53 lines (42 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
use strict;
use warnings;
use English qw(-no_match_vars);
use IO::File;
use POSIX qw(EXIT_FAILURE EXIT_SUCCESS);
sub printFailList {
my ($failList, $errNoList) = @_;
for (my $i = 0; $i < scalar(@$failList); $i++) {
my $failPath = $failList->[$i];
my $errNo = $errNoList->[$i];
local $ERRNO = $errNo;
printf(STDERR "ERROR deleting \"%s\": %s\n", $failPath, $ERRNO);
}
return;
}
sub main {
my (@argv) = @_;
my @failList = ( );
my @errNoList = ( );
my $fail = sub {
my ($path, $errNo) = @_;
push(@failList, $path);
push(@errNoList, $errNo);
return 0;
};
my ($fileCount, $successCount) = (0, 0);
foreach my $arg (@argv) {
if (defined(my $f = $arg)) {
if (my $fh = IO::File->new($f, 'r')) {
while (my $path = <$fh>) {
chomp($path);
$fileCount++;
$successCount += (unlink($path) || $fail->($path, int($ERRNO)));
}
}
}
}
printFailList(\@failList, \@errNoList);
return ($fileCount == $successCount) ? EXIT_SUCCESS : EXIT_FAILURE;
}
exit(main(@ARGV)) unless (caller());