perl -we '/(.*)\./&&rename"$1.foo","$1.bar"for<*.foo>'
Probably not the best way (2 foos), but it works.
Hope this helps,,,
Aziz,,, | [reply] [d/l] |
There is a rename function in Perl. Who needs a module?
| [reply] |
Not that it seems to be an issue in this particular case, but rename may have issues with moving files across filesystems, etc., which is why File::Copy is standard with the distribution.
And if you wanted a recursive Perl-y solution, you'dn use File::Find.
pedantically,
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>);
+$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth
+er_name\n"'
| [reply] [d/l] [select] |
What OS and shell? I wouldn't even use Perl. I'd just say "rename *.bob *.fred" on the command line. Or, if it has subdirs, "global rename *.bob *.fred". | [reply] |
| [reply] [d/l] |
Hello
"I wouldn't even use Perl. I'd just say "rename *.bob *.fred" on the command line."
But you are using Perl, since rename is written in Perl :-)
Aziz,,,
Update:Many people seem to vote without reading the followups, so, here it is:
RENAME(1) Perl Programmers Reference Guide RENAME(1)
NAME
rename - renames multiple files
SYNOPSIS
rename [ -v ] perlexpr [ files ]
DESCRIPTION
"rename" renames the filenames supplied according to the
rule specified as the first argument. The perlexpr argu?
ment is a Perl expression which is expected to modify the
"$_" string in Perl for at least some of the filenames
specified. If a given filename is not modified by the
expression, it will not be renamed. If no filenames are
given on the command line, filenames will be read via
standard input.
For example, to rename all files matching "*.bak" to strip
the extension, you might say
rename 's/\e.bak$//' *.bak
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
[snip]
AUTHOR
Larry Wall
Aziz,,, | [reply] [d/l] |
No, it's a shell intrinsic command.
[D:\Program Files\4nt]rename /?
Rename files or subdirectories.
RENAME [/A:[[-]rhsda] /E /I"text" /NPQST] old_name... new_name
/A:(ttribute select) /P(rompt)
/E (no error messages) /Q(uiet)
/I (match description) /S(ubdirectory)
/N(othing) /T(otal)
[D:\Program Files\4nt]
| [reply] [d/l] |