[Pdx-pm] command line question
Thomas J Keller
kellert at ohsu.edu
Mon Jul 12 16:24:19 CDT 2004
That doesn't work for this problem: replacing whitespace in filenames.
But thanks.
On Jul 12, 2004, at 2:16 PM, Colin Kuskie wrote:
> On Mon, Jul 12, 2004 at 02:10:37PM -0700, Thomas J Keller wrote:
>> This seems like one of those easy things easier ...things
>> I want to rename all the files in a directory substituting an
>> underscore for any spaces in the filename. I can write a program using
>> IO::Dir, But it seems like that should be doable from the command
>> line.
>> Help?
>> Thanks,
>> Tom K.
>
> The original perl distribution used to include a program called rename
> that allowed you to pass a line of perl code that would modify each
> filename in any way you want.
>
> ren 'tr/ /_/;' *
>
>
> #!/usr/local/bin/perl
>
> #Usage: ren perlexpr [files]
>
> ($op = shift) or die "Usage: ren perlexpr [filenames]\n";
>
> if (!@ARGV) {
> @ARGV = <STDIN>;
> chop(@ARGV);
> }
>
> for (@ARGV) {
> $was = $_;
> eval $op;
> die $@ if $@;
> unless ($was eq $_) {
> rename($was,$_) or die "Unable to rename $was: $!\n";
> }
> }
>
> =head1 NAME
>
> B<ren> - use a perl expression to rename multiple files
>
> =head1 SYNOPSIS
>
> B<ren> perl_expression [files]
>
> =head1 DESCRIPTION
>
> B<Ren> uses a perl expression to rename multiple files. For more
> information about
> perl expressions, consult the perl man pages, F<Learning Perl> by
> Randal
> Schwartz, F<Programming Perl> by Larry Wall, or your local friendly
> Perl programmer.
>
> For example, to rename all files foo.* to bar.*, use
>
> ren 's/foo/bar/;' foo.*
>
>
> =head1 AUTHORS
>
> Randal Schwartz, Larry Wall
>
> =head1 DATE
>
> October 11, 1996
>
> =cut
>
More information about the Pdx-pm-list
mailing list