-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbulk_delete_files_in_list.pl
54 lines (42 loc) · 1.09 KB
/
bulk_delete_files_in_list.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
#!/usr/bin/env perl
# Deletes files in input list.
# Usage:
# perl bulk_delete_files_in_list.pl
# [file containing list of paths of files to delete, one per line]
use strict;
use warnings;
my $list_of_files_to_delete = $ARGV[0]; # file containing list of paths of files to delete, one per line
# verifies that list of input files exists and is non-empty
if(!$list_of_files_to_delete)
{
print STDERR "Error: no input file list provided. Exiting.\n";
die;
}
if(!-e $list_of_files_to_delete)
{
print STDERR "Error: input file list does not exist:\n\t"
.$list_of_files_to_delete."\nExiting.\n";
die;
}
if(-z $list_of_files_to_delete)
{
print STDERR "Error: input file list is empty:\n\t"
.$list_of_files_to_delete."\nExiting.\n";
die;
}
open FILES_TO_DELETE, "<$list_of_files_to_delete" || die "Could not open $list_of_files_to_delete to read; terminating =(\n";
while(<FILES_TO_DELETE>) # for each line in the file
{
chomp;
if($_ =~ /\S/)
{
my $file_path = $_;
if(-e $file_path) # if file exists
{
# delete file
`rm $file_path`;
}
}
}
close FILES_TO_DELETE;
# March 31, 2022