History for RenamingFiles
changed:
-
This is a script for renaming files with a regexp.
I found this on the 'net. I think the original source was the Perl
Cookbook (or something like that). It is trivial to change it so that
it copies instead of renaming.<br>
<a href="rename">rename</a><br>
<pre><br><img src="rename">#!/usr/bin/perl<br><br>$op = shift or die "Usage: rename expr [files]\n";<br><br>chomp(@ARGV = <STDIN>) unless @ARGV;<br><br>for (@ARGV) {<br> $was = $_;<br> eval $op;<br> die $@ if $@;<br> rename($was, $_) unless $was eq $_;<br>}<br><br># The first argument to the script should be a Perl expression that will be<br># evaluated for every file named on the command line, or (if there are none)<br># every file on the standard input stream, one per line. When the expression<br># is evaluated, $_ (the default variable) will contain a file name. If<br># evaluating the expression changes $_, the file will be renamed to the new<br># value of $_.<br>#<br># Examples:<br>#<br># Change spaces to underscores:<br># rename 's/ /_/g'<br># or<br># rename 'tr/ /_/'<br>#<br># Change .foo extensions to .bar:<br># rename 's/\.foo$/.bar/' *<br>#<br># Change .foo to .bar in an entire directory tree:<br># find . -type f | rename 's/\.foo$/.bar/'<br>#<br># Append a .bak extension to all .cc files:<br># rename '$_ .= ".bak" if /\.cc$/' *<br></STDIN></pre>
From pbier Fri Feb 16 16:15:34 +1300 2007
From: pbier
Date: Fri, 16 Feb 2007 16:15:34 +1300
Subject:
Message-ID: <20070216161534+1300@www.cmiss.org>
This script did not work for me so I grabbed the original from the perl cook book
http://www.unix.org.ua/orelly/perl/cookbook/ch09_10.htm