Completed common tasks and idioms.
1 parent 474f088 commit 3bb0a6cea85d1988ffbbc6c816fc96c1b02d1c92
@tundra tundra authored on 7 Apr 2010
Showing 1 changed file
View
96
tren.rst
 
COMMON TASKS AND IDIOMS
-----------------------
 
With a program as feature dense as **tren**, it's not
possible to document every possible use case. The following
examples cover many common applications of the program.
With a program as feature dense as **tren**, it's not possible to
document every possible use case. The following examples cover many
common applications of the program.
 
- Literal String Replacement
 
Sometimes, all you want to do is replace a single
substring in a name::
 
tren.py -r Old=New OldRecords-OldPeople # Yields: NewRecords-OldPeople
 
 
- Replacing Or Removing All Instances Of A String
 
Sometimes you want to replace every instance of the string::
 
tren.py -i : -r Old=New OldRecords-OldPeople # Yields: NewRecords-NewPeople
 
 
- Changing A File's "Extension" Suffix
 
Common where the suffix of a file is significant to an applications
program::
 
tren.py -i -1 -r .jpeg=.jpg *.jpeg
 
 
- Replace Spaces In A Filename With Underbars
 
Even though spaces are allowed in file names in most OSs, they're
a pain::
 
tren.py -i : -r " "=_ *
 
 
- Appending- Or Prepending Strings To An Existing File Name
 
Often, you want to keep the existing name, but add to it::
 
tren.py -r =Prefix-/FNAME/
tren.pu -r =/FNAME/-Suffix
 
 
- Ordering File Names By Last Modification Time
 
It's nice to be able to see files in the order they
were last modified. Usually, we preserve the old name
when doing this::
 
tren.py -r =/+MTIME::001/-/FNAME/
 
- Ordering File Names By Modification Time Within Date
 
Sometimes, what we want is the order of modification
*within* the date it was changed::
 
tren.py -r =/MYEAR/-/MMON/-/MDAY/-/+MDATE::001/-/FNAME/ *
 
- Ordering File Names By Size
 
This is handy if we want a directory listing to list the files in
size order::
 
tren.py -r =/SIZE/-/FNAME/ *
 
- Undoing A Previous Renaming
 
In complex renamings, sometimes the only way to get back to your
original names is to examine the renaming log. But in some cases
it's pretty automatic::
 
tren.py -r ='/$LOGNAME/'-/FNAME/ *
 
This can be undone by::
 
tren.py -r '/$LOGNAME/'-= *
 
Generally, if you can isolate the newly introduced text of the
renaming and place use it as the ``old`` string in a renaming
request, this will work.
 
 
ODDS AND ENDS
-------------
You'll need to put proper quoting around it to perserve if for
**tren** to see, whether in a renaming request, an alphabet
definition, or some part of a sequence renaming token.
 
- **tren** will attempt to do any requested renaming. However,
if you manage to embed some character in the new name that
the operating system doesn't like, the renaming will fail and
you'll be notified of the fact. Notwithstanding the fact that
you can do all manner of clever things with **tren**, some
restraint is called for when constructing new file- or directory
names.
- Most shells don't care if you leave a space between an option
and its argument. It's a really good idea to do so as a matter
of habit, especially when dealing with a complex command line
driven tool like **tren**.
 
- **tren** will attempt to do any requested renaming. However, if you
manage to embed some character in the new name that the operating
system doesn't like, the renaming will fail and you'll be notified
of the fact. Notwithstanding the fact that you can do all manner of
clever things with **tren**, some restraint is called for when
constructing new file- or directory names.
 
- **tren** will prevent you from trying to rename something to a null
string or a name too long for the operating system. Mostly this is
not an issue *unless* you managed to concoct a renaming request that
you CAN LOSE FILES THIS WAY!!!**. The smart move here is to use
test mode and make sure your proposed renaming isn't going to
require deeply recursive backups.
 
- Save the output from your **tren** runs in logs. That way, if you
have to unwind a renaming gone bad, you'll have a record of what was
done.
 
- The use of ``-bf`` is **strongly** discouraged and is provided only
for the most sophisticated and careful users.
 
 
 
BUGS, MISFEATURES, OTHER
------------------------
 
-----------------------------
 
::
 
$Id: tren.rst,v 1.179 2010/04/07 21:16:51 tundra Exp $
$Id: tren.rst,v 1.180 2010/04/07 21:45:29 tundra Exp $
 
You can find the latest version of this program at:
 
http://www.tundraware.com/Software/tren