-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_sbg_project_files_to_delete.pl
executable file
·94 lines (72 loc) · 2.25 KB
/
select_sbg_project_files_to_delete.pl
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env perl
use warnings;
use strict;
use English qw(-no_match_vars);
use Getopt::Long qw(:config no_ignore_case);
use IO::File;
our $VERSION = 0.1;
my $listfile;
my $outfile;
my $md5;
my $index;
my $log;
my $filter;
my $doc = <<END;
A script to filter out the unwanted files to target for deletion.
Many files are either redundant or not necessary to be kept and
can be easily regenerated. When looking to save on file counts,
for example when manually exporting lots of files, this might help.
MD5 files in the Legacy project are redundant (they're in the manifest).
Index files (bai, tbi, crai) can easily be recreated.
Other files could be selected through regular expression.
This works on recursive file listing generated with sbg_project_manager.
It does not actually delete the files. Use the output file of selected
files as input to sbg_project_manager to delete.
Options
--list <file> The list of all files in the project
generate with sbg_project_manager.pl
--out <file> The output file written
-m Select md5 files (.md5)
-i Select index files ( .bai .tbi .crai )
-l Select log files (.log)
-f <regex> Custom file filter as Perl Regular Expression
END
if (@ARGV) {
GetOptions(
'list=s' => \$listfile,
'out=s' => \$outfile,
'm!' => \$md5,
'i!' => \$index,
'l!' => \$log,
'f=s' => \$filter,
) or die " bad options! Please check\n $doc\n";
}
else {
print $doc;
exit 0;
}
my $infh = IO::File->new($listfile)
or die " unable to read $listfile! $OS_ERROR";
my $outfh = IO::File->new($outfile, '>')
or die " unable to write $outfile! $OS_ERROR";
# header
my $header = $infh->getline;
$outfh->print($header);
# files
my $count = 0;
while (my $line = $infh->getline) {
chomp $line;
my $keep = 0;
$keep++ if ( $md5 and $line =~ /\.md5$/ );
$keep++ if ( $index and $line =~ /\. (?: bai | tbi | crai ) $/xi );
$keep++ if ( $log and $line =~ /\.log$/ );
$keep++ if ( $filter and $line =~ /$filter/ );
if ($keep) {
$outfh->printf("%s\n", $line);
$count++;
}
}
# finish
$infh->close;
$outfh->close;
printf "\n Selected %d files written to %s\n", $count, $outfile;