-
Notifications
You must be signed in to change notification settings - Fork 0
/
respace.pl
executable file
·85 lines (64 loc) · 1.72 KB
/
respace.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
#!/usr/bin/perl
#
# Re-Spaces BiCapitalized filenames.
#
# Author: Peter Keel <[email protected]>
# Date: 2013-07-06?
# Revision: 2020-05-06
# Version: 0.4
# License: Public Domain
# URL: http://seegras.discordia.ch/Programs/
#
# Does not exactly use spaces, but rather underscores.
#
use strict;
use Getopt::Long;
use Pod::Usage;
my $needshelp;
my $dname;
my @dir_contents;
my $filename;
my $oldname;
&Getopt::Long::Configure( 'pass_through', 'no_autoabbrev');
&Getopt::Long::GetOptions(
'help|h' => \$needshelp,
);
if (!$ARGV[0]) {
$dname = ".";
} else {
$dname=$ARGV[0];
}
if ($needshelp) {
pod2usage(1);
}
opendir(my $in_dir, $dname) || die "I am unable to access that directory...Sorry";
@dir_contents = readdir($in_dir);
closedir($in_dir);
@dir_contents = sort(@dir_contents);
foreach my $filename (@dir_contents) {
if ($filename ne ".." and $filename ne ".") {
$oldname = $filename;
$filename =~ s/([A-Z-])/_$1/g;
# fixes
$filename =~ s/^_//g; # don't start a filename with an underscore
$filename =~ s/^-//g; # never start a filename with a dash
rename ("$dname/$oldname", "$dname/$filename") unless (($filename eq $oldname) || (-e "$dname/$filename")) ;
}
}
__END__
=head1 NAME
respace - re-space BiCapitalized filenames
=head1 SYNOPSIS
B<This program> [options] [directory ...]
Options:
-h|--help
=head1 OPTIONS
=over 8
=item B<-h|--help>
Print a brief help message and exit.
=back
=head1 DESCRIPTION
B<This program> will re-space bicapitalized filenames by prefixing
upper-case letters with underscores. It processes all files of the
directory you're in, unless given another directory.
=cut