Acme-Cavaspazi
view release on metacpan or search on metacpan
bin/cavaspazi view on Meta::CPAN
#!/usr/bin/env perl
# PODNAME: cavaspazi
# ABSTRACT: a simple script to remove spaces from filenames or file contents
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use File::Spec;
my $rename = 0;
my $substitute = 0;
my $dry_run;
my $verbose;
my $help;
GetOptions(
'rename|r' => \$rename,
'substitute|s' => \$substitute,
'dry-run|n' => \$dry_run,
'verbose' => \$verbose,
'h|help' => \$help,
);
pod2usage({-exitval => 0, -verbose => 2}) if $help;
my $cnt = 0;
my $tot = scalar @ARGV;
bin/cavaspazi view on Meta::CPAN
my $dirname = dirname($file);
# check if file exists
if (!-e $file) {
print STDERR "$cnt/$tot File $file does not exist. Skipping...\n";
next;
}
if ($verbose) {
my $type = -d $file ? 'directory' : 'file';
print STDERR "$cnt/$tot Processing $dirname -> $basename [$type]...\n"
}
if ($rename) {
my $new_file = $basename;
$new_file =~ s/ /_/g;
my $dest = File::Spec->catfile($dirname, $new_file);
if ($dry_run) {
print "#mv \"$file\" \"$dest\"\n";
} else {
rename "$file", "$dest" or die "Can't rename $file to $dest: $!";
}
}
elsif ($substitute) {
if (-d $file) {
print STDERR "Skipping: substitute only works with files...\n" if ($verbose);
next;
}
open my $fh, '<', $file or die "Can't open $file: $!";
my $content = do { local $/; <$fh> };
close $fh;
bin/cavaspazi view on Meta::CPAN
version 1.0.3
=head1 SYNOPSIS
cavaspazi [-r|-s] file1 file2 ...
=head1 SUMMARY
Cavaspazi - a simple script to remove spaces from filenames or file contents.
To remove spaces from filenames use the C<-r, --rename> option.
To remove spaces from files, use the C<-s, --substitute> option.
=head1 OPTIONS
=over 4
=item B<-r, --rename>
Rename files by removing spaces from their names.
=item B<-s, --substitute>
Substitute spaces with underscores in the contents of the files.
=item B<-n, --dry-run>
Do not actually rename or substitute anything, just print what would be done.
=item B<-v, --verbose>
Print what is being done.
=item B<-h, --help>
Print a brief help message and exits.
=back
( run in 0.539 second using v1.01-cache-2.11-cpan-e9daa2b36ef )