diff --git a/tren.rst b/tren.rst index 245fb68..75dada6 100644 --- a/tren.rst +++ b/tren.rst @@ -897,6 +897,61 @@ invocation. +Limiting Renaming To Only Part Of Name +====================================== + +Sometimes you just want to rename a *part* of a file- or directory +name (aka a name "substring"). As described below, you can use a +Regular Expression to do this, but this can be complicated and is +often overkill for simple substitutions. **tren** gives you the +ability to limit the renaming action to a "targeted" portion of the +name using the ``-T`` option. You simply supply a "slice" describing +the portion of the name to be renamed:: + + tren.py -i: -T :3 -r=x abcdef.text # -> xdef.text + tren.py -i: -T :-4 -re=E abcdef.text # -> abcdEf.text + +It's important to understand how ``-i`` and ``-T`` interact. Even +though all instances of a matching old string are specified via the +``-i:`` option, the ``-T`` option that follows it limits the portion +of the name being considered for renaming. For instance, in the +second example, removing the ``-T`` targeting gives us:: + + tren.py -i: -re=E abcdef.text # -> abcdEf.tExt + +In summary, ``-T`` defines what substring of the full name +is a candidate for renaming. All other renaming operations +like ``-i``, ``-r``, and so on operate *only upon the substring +specified by* ``-T``. + + +More About Slice Notation +========================= + +Both the ``-i`` and ``-T`` options use "slice" notation so +it's useful to understand a bit more about how "slices" are +constructed. + +.. NOTE:: Although both options use slice notation, they mean very + different things. In the case of ``-i``, the slice specifies + which *instances* of an old string are to be replaced. + In the case of ``-T``, the slice defines which *characters* + in the original file name are "targeted" for renaming. + +**tren** is written in the Python programing language. The slice +notation is lifted directly from that language. if you're a Python +programmer, you can skip this section :) + +Imagine you have a filename like this:: + + abcdef.txt + + + + + + + Multiple Substitutions ====================== @@ -2896,7 +2951,7 @@ :: - $Id: tren.rst,v 1.193 2010/09/08 19:50:16 tundra Exp $ + $Id: tren.rst,v 1.194 2010/10/18 19:06:29 tundra Exp $ You can find the latest version of this program at: