l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
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
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>.

Attachment: pgp00011.pgp
Description: PGP signature



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
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:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.