l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jul 30 08:53

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] python: slicing extensions from file names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] python: slicing extensions from file names

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

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

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:

Attachment: pgp00011.pgp
Description: PGP signature

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.