[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: RFS: patmv -- a bulk renaming tool

>   > I'd like to request a sponsor for my "patmv" package.  patmv is a Perl
>   > script that can be used to do bulk renames on files based on a Perl
>   > expression ("pattern").  I've been using this script for about 10
>   > years, and it has a small following among current and former
>   > co-workers.  The idea was inspired by a short example that was
>   > included with perl 5.000 or one of its betas, but my script is an
>   > expansion on the original concept.
>   Can you clarify what the difference is between this script and the
>   'rename' script currently including in the Debian perl package?
>   All of the examples you gave, as far as I can tell, would work
>   just as well with the 'rename' that is already in Debian.

Hmm.  Looks like rename and patmv have the same common ancestor.  I
didn't realize this already existed, though I tried digging for it in
the perl sources.  (I didn't know what it was called, and I didn't
think to look in the debian/ directory which is where rename is in the
Debian perl distribution.)

There are several differences, though: patmv has logic to handle
recursive renames in an intelligent way and has options for
manipulating the whole path or the last component as an option.  In my
opinion, it also handles file existence cases more robustly and
generates more useful output.

% mkdir -p z
% cd z

With rename:

% mkdir WORK; touch WORK/{1,2,3}.TXT
% rename -v tr/A-Z/a-z/ `find WORK -print`
WORK renamed as work
Can't rename WORK/1.TXT work/1.txt: No such file or directory
Can't rename WORK/2.TXT work/2.txt: No such file or directory
Can't rename WORK/3.TXT work/3.txt: No such file or directory

With patmv:

% rm -rf work
% mkdir WORK; touch WORK/{1,2,3}.TXT
% patmv tr/A-Z/a-z/ `find WORK -print`
mv WORK work
mv work/1.TXT work/1.txt
mv work/2.TXT work/2.txt
mv work/3.TXT work/3.txt

patmv generates output that could be re-executed if needed (though
I've seldom used this feature) and that handles the need for quoting

% touch "Someone's Goofy Filename"
% patmv "tr/A-Z '/a-z_-/" S*
mv 'Someone'\''s Goofy Filename' someone-s_goofy_filename

patmv handles existing file names by prompt the user unless it can't
(in which case it fails without overwriting) or --force is given (in
which case it just renames the file):

% touch 1 2
% rename s/1/2/ 1
1 not renamed: 2 already exists

% patmv s/1/2/ 1
2 exists.  Overwrite? y
mv 1 2

patmv can read files from stdin as well as taking files on the
command-line.  For example, one could convert a large RCS-based source
tree to a CVS repository with something like (untested):

% find . -type f -name '*,v' | grep RCS/ > /tmp/1
% tar -c --files-from /tmp/1 -f - | (cd /my/cvs-repo; tar xf -)
% cd /mn/cvs-repo
% find . -type f -print | patmv -w s,RCS/,,

My copyright says that the software can be redistributed and used for
any purpose, which is less restrictive than the Aristic license.  At
the time I wrote my version of the script, I wrote it from scratch
without using any of the original example code which was only a few
lines long anyway.  I could probably be convinced to use the Artistic
license, though for something so short, I see no need to maintain any
kind of artistic control.  (I don't view myself as having violated the
original copyright since I didn't use any of the code and since the
idea was so simple, but if you disagree, by all means let me know.)


Reply to: