On Tue, Jul 29, 2003 at 10:46:23AM -0700, David Siedband wrote: > I'd like to find a way to slice the extension off of a file name in python. > > That is, I'd like to slice everything after the first period in the file > name.
Most people use regular expression to do this sort of job. I don't know
python, but here is a perl example:
foreach $filename (@array_of_filenames) {
$filename ~= s/\..+$//;
# $filename now contains new name. insert code to use new name here
}
Perhaps someone who knows python would be kind enough to provide a python
example.
By the way, renaming files by removing a specific extension is easy in the
shell. To rename bunch of files named <name>.HTM to <name>.html, try
for file in *.HTM; do
mv $file `basename $file .HTM`.html
done
But removing any extension regardless of its content requires fuzzy matching,
such as a regular expression.
--
Henry House
The unintelligible text that may follow is a digital signature.
See <http://hajhouse.org/pgp> for information. My OpenPGP key:
<http://hajhouse.org/hajhouse.asc>.
pgp00000.pgp
Description: PGP signature
