This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.002_01: lib/File/Basename.pm
[perl5.git] / eg / rename
CommitLineData
a687059c 1#!/usr/bin/perl
00bf170e
LW
2'di';
3'ig00';
4#
79072805 5# $RCSfile: rename,v $$Revision: 4.1 $$Date: 92/08/07 17:20:30 $
00bf170e
LW
6#
7# $Log: rename,v $
a687059c
LW
8
9($op = shift) || die "Usage: rename perlexpr [filenames]\n";
9f68db38 10if (!@ARGV) {
00bf170e
LW
11 @ARGV = <STDIN>;
12 chop(@ARGV);
a687059c
LW
13}
14for (@ARGV) {
15 $was = $_;
16 eval $op;
17 die $@ if $@;
18 rename($was,$_) unless $was eq $_;
19}
00bf170e
LW
20##############################################################################
21
22 # These next few lines are legal in both Perl and nroff.
23
24.00; # finish .ig
25
26'di \" finish diversion--previous line must be blank
27.nr nl 0-1 \" fake up transition to first page again
28.nr % 0 \" start at page 1
29';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############
30.TH RENAME 1 "July 30, 1990"
31.AT 3
32.SH NAME
33rename \- renames multiple files
34.SH SYNOPSIS
35.B rename perlexpr [files]
36.SH DESCRIPTION
37.I Rename
38renames the filenames supplied according to the rule specified as the
39first argument.
40The argument is a Perl expression which is expected to modify the $_
41string in Perl for at least some of the filenames specified.
42If a given filename is not modified by the expression, it will not be
43renamed.
44If no filenames are given on the command line, filenames will be read
45via standard input.
46.PP
47For example, to rename all files matching *.bak to strip the extension,
48you might say
49.nf
50
51 rename 's/\e.bak$//' *.bak
52
53.fi
54To translate uppercase names to lower, you'd use
55.nf
56
57 rename 'y/A-Z/a-z/' *
58
59.fi
60.SH ENVIRONMENT
61No environment variables are used.
62.SH FILES
63.SH AUTHOR
64Larry Wall
65.SH "SEE ALSO"
66mv(1)
67.br
68perl(1)
69.SH DIAGNOSTICS
70If you give an invalid Perl expression you'll get a syntax error.
71.SH BUGS
72.I Rename
73does not check for the existence of target filenames, so use with care.
74.ex