update March 8, 2021
NAME
bl_rename.py - Rename files by
replacing one pattern with a new pattern. The list of files to be
renamed is supplied in an input file.
SYNOPSIS
bl_rename.py
--replace oldpattern newpattern
namefile
bl_rename.py --chblanks
newpattern namefile
bl_rename.py --noblanks
namefile
bl_rename.py
--camel namefile
DESCRIPTION
For each file listed in namefile whose name
contains oldpattern, rename the file, replacing oldpattern with
newpattern.
--replace - replace oldpattern with newpattern
--chblanks - replace blanks with newpattern
--noblanks - remove all blanks
--camel - Change each nonblank substring to camel case ie.
first letter capitalized, all other letters in lowercase, and
remove all blanks.
oldpattern - A substring of the filename to be replaced
newpattern - A substring to replace the oldpattern. If
empty, the target is simply deleted from the name. The empty
string must be enclosed in single quotes ie. ''
namefile
- a file listing filenames in the current working directory to be
changed . At least 1 file must be specified. Each name must be on
a separate line.
This command is intended to be a workalike for the Linux rename
command. bl_rename.py uses the Python os.replace command to rename
files.
EXAMPLE
Given the following files in the current working
directory, as listed in namefile:
namefile:
testfile1.text
testfile2.text
testfile3.text
testfile4.text
bl_rename.py --replace text txt namefile
changes the names to
testfile1.txt
testfile2.txt
testfile3.txt
testfile4.txt
bl_rename.py --replace ile '' namefile
changes the names to
testf1.txt
testf2.txt
testf3.txt
testf4.txt
Given
namefile:
blanks in file names is a bad practice
Because you have to escape file names using quotes
bl_rename.py --noblanks namefile
results in
blanksinfilenamesisabadpractice
Becauseyouhavetoescapefilenamesusingquotes
while
bl_rename.py --camel namefile
results in
BlanksInFileNamesIsABadPractice
BecauseYouHaveToEscapeFileNamesUsingQuotes
AUTHOR
Dr. Brian Fristensky
Department of Plant Science
University of Manitoba
Winnipeg, MB Canada R3T 2N2
brian.fristensky@umanitoba.ca
http://home.cc.umanitoba.ca/~frist