The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

pbr - Perl-based Batch Rename

SYNOPSIS

pbr [-c] [-d destination_directory] [-D] [-i] [-t] [-v] [-w] PerlExpression Files ...

See below for description of the switches.

DESCRIPTION

pbr is a perl-based batch renaming tool. Normally you wouldn't care about the implementation language of a tool, but in this case proper usage depends on your knowledge of perl.

The first argument to this program should be a perl expression that modifies $_. The remaining arguments are files that will potentially be renamed.

Each file name is temporarily placed in $_. The given expression is then evaled. Only if executing the expression results in the file name being changed, is the file renamed accordingly.

For example, if one of your input file names is foo.txt and your expression s/o/O/g, the renamed file will be fOO.txt.

On the command line, this would appear as:

   pbr s/o/O/g foo.txt

If your input file above was bar.txt, no change or rename would be made.

OPTIONS

-c

Perform a copy instead of a rename.

-d destination_directory

The destination for a renamed file will be the modified file's base name prepended with the given destination directory.

Example:

   pbr -vd new_dir/ s/o/O/g foo.txt
   move: foo.txt => new_dir/fOO.txt
-D

Create directories if necessary.

-i

Prompt the user for confirmation prior to performing the rename (interactive mode).

-t

No renames will be performed (test mode). Implies -v.

-v

Print diagnostic information concerning the renaming of files.

-w

Store the whole path and file into $_. By default only the base name is put in $_. This allows your expression to see and modify the path.

Example:

   pbr -vw s/o/O/g foo/foo.txt
   move: foo/foo.txt => fOO/fOO.txt

Without the -w the above the expression would only operate on the base name of the file, resulting in the modified file name being 'foo/fOO.txt'.

EXAMPLES

o

Upper-case base name with substitution.

   pbr -v 's/(.)/\U$1/g' dir/abc123.txt
   move: dir/abc123.txt => dir/ABC123.TXT
o

Upper-case (ASCII-only) base name with transliteration.

   pbr -v tr/a-z/A-Z/ dir/abc123.txt
   move: dir/abc123.txt => dir/ABC123.TXT
o

Upper-case base name with assignment, move to specified directory.

   pbr -vd new_dir '$_ = uc' dir/abc123.txt
   move: dir/abc123.txt => new_dir/ABC123.TXT
o

Upper-case path and base name with assignment, create directory if necessary.

   pbr -vwD '$_ = uc' dir/abc123.txt
   move: dir/abc123.txt => DIR/ABC123.TXT
o

Replace directory separators with underscores.

   pbr -vw 'tr/\//_/d' dir/abc123.txt
   move: dir/abc123.txt => dir_abc123.txt

TODO

o

Create a plugin system where -p indicates the expression is replaced by a plugin name. The plugin name would be looked up in $HOME/.pbr_plugin/ or /etc/pbr_plugin. The plugin would be required and a sub with the same name would be called for each file.

AUTHOR

Daniel B. Boorstein <danboo@cpan.org>

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 198:

You forgot a '=back' before '=head1'

Around line 237:

You forgot a '=back' before '=head1'

Around line 248:

You forgot a '=back' before '=head1'