tren - Advanced File Renaming
tren.py [-dhipqtvx] [-s string] [-r old=new]... file|dir file|dir ...
Warning
tren is a powerful file and directory renaming tool. It is
entirely possible to clobber files by renaming one file so as to
delete another one with that same name. Be sure you know
what you're about to do. If you're not, run the program in test
mode (invoke with the -t
option) to see what could happen.
You have been warned!
tren is a general purpose file and directory renaming tool. Unlike
commands like mv
, tren is particularly well suited for
renaming batches of files and/or directories with a single command
line invocation.
tren supports two kinds of renaming operations, String Substitution and Rename By Date.
String substitution is handy when you have files and directories that have a common set of characters in them you'd like to change. For instance:
tren -r .Jpeg=.jpg files.Jpeg
would rename all files (or directories) whose names contained the string
.Jpeg
and replace it with.jpg
. It's important to realize that such a substitution takes place anywhere in the filename, not just at the end or "extension" (as it is called in Windows).By default, only the first instance of the string is replaced in the name, but you can use the
-g
option to replace all instances of the old string withthe new one.Ordinarily tren treats both the old string you specify with the
-r
option literally. However, it is sometimes handy to be able to write a regular expression to specify what you want replaced. If you specify the-x
option, tren will treat your old string as a Python style regex, compile it (or try to anyway!) and use it to select which strings to replace. This makes it much easier to rename files that have repeated characters or patterns, and groups of files that have similar, but not idential strings in their names you'd like to replace.
-d Rename by date sequence. (Default: Rename via string replacement.) -g Replace all instances (greedy replace) of the old string with the new. -h Print help information. -i Use ISO date format when renaming by date sequence. (Default: "YYYYMMDD") -p Prepend, do not replace, file name with date sequence. (Default: Replace filename) -q Quiet mode, do not show progress. (Default: Display progress) -s string File "extension" delimiter string. (Default: ".") -r Replace "oldstring" with "newstring" in filenames. -t Test mode, don't rename, just show what the program would do (ignores -q). -v Print detailed program version information and exit. -w Turn off warnings about potentially overwriting existing files or directories. (Default: Warn if target exists.) -x Treat the old string in a -r
replacement as a Python style regular expression for matching purposes. (Default: Treat the old string as literal text)
You must have a reasonably current version of Python installed.
None known as of this release.
tren is Copyright (c) 2010 TundraWare Inc.
For terms of use, see the tren-license.txt
file in the
program distribution. If you install tren on a FreeBSD
system using the 'ports' mechanism, you will also find this file in
/usr/local/share/doc/tren
.
Tim Daneliuk
tren@tundraware.com
$Id: tren.rst,v 1.103 2010/01/15 00:18:43 tundra Exp $
You can find the latest version of this program at:
http://www.tundraware.com/Software/tren