update December 13, 2024
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 --ltruncate
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
--ltruncate - truncate filename before and
including first occurence of 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
1) 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
2) Given
(This is only slightly contrived, but true in the sense that
the original filenames are lost amongst the junk added to them.
The filenames produced when Desire To Learn creates a Zip
archive are MUCH longer!)
namefile:
00123 45678 Download Dec. 12, 2024 518 PM-file1.txt
45361 45678 Download Dec. 12, 2024 518 PM-file2.txt
bl_rename.py --ltruncate PM- namefile
changes the names to
file1.txt
file2.txt
3) Given
namefile:
blanks in file names is a bad practice.docx
Because you have to escape file names using quotes.docx
bl_rename.py --noblanks namefile
results in
blanksinfilenamesisabadpractice.docx
Becauseyouhavetoescapefilenamesusingquotes.docx
while
bl_rename.py --camel namefile
results in
BlanksInFileNamesIsABadPractice.docx
BecauseYouHaveToEscapeFileNamesUsingQuotes.docx
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