-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfix-names.pl
56 lines (42 loc) · 1.02 KB
/
fix-names.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
#!/usr/bin/perl
=pod
=head1 NAME
fix_names.pl - Fix bad file names
=head1 SYNOPSIS
fix_name.pl <file> [<file> ...]
=head1 DESCRIPTION
The I<fix_names.pl> command renames files with bad names into ones with good names.
=head1 AUTHOR
Steve Oualline, E<lt>[email protected]<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
foreach my $file_name (@ARGV)
{
# Compute the new name
my $new_name = $file_name;
$new_name =~ s/[ \t]/_/g;
$new_name =~ s/[\(\)\[\]<>]/x/g;
$new_name =~ s/[\'\`]/=/g;
$new_name =~ s/\&/_and_/g;
$new_name =~ s/\$/_dol_/g;
$new_name =~ s/;/:/g;
# Make sure the names are different
if ($file_name ne $new_name)
{
# If a file already exists by that name
# compute a new name.
if (-f $new_name)
{
my $ext = 0;
while (-f $new_name.".".$ext)
{
$ext++;
}
$new_name = $new_name.".".$ext;
}
print "$file_name -> $new_name\n";
rename($file_name, $new_name);
}
}