473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to get a filename's extension

Hello all,

I am new to python and I am having some difficulty obtaining the
extension of a file. I was looking at the re.match module but I am
completely overwhelmed by regular expressions. Is there an easier way
to get the extension for a file name like:

this.is.my.file.avi

I would just like to pull out the 'avi'

your help is greatly appreciated! :)

Sep 4 '06 #1
1 5394
On 3 Sep 2006 17:46:32 -0700, Su*******@gmail.com <Su*******@gmail.comwrote:
Hello all,

I am new to python and I am having some difficulty obtaining the
extension of a file. I was looking at the re.match module but I am
completely overwhelmed by regular expressions. Is there an easier way
to get the extension for a file name like:

this.is.my.file.avi

I would just like to pull out the 'avi'

your help is greatly appreciated! :)
>>import os
os.path.splitext('this.is.my.file.avi')
('this.is.my.file', '.avi')

--
I like python!
My Blog: http://www.donews.net/limodou
UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad
UliPad Maillist: http://groups.google.com/group/ulipad
Sep 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
1
by: hokiegal99 | last post by:
I've written a small script (with much help from this list) that searches through a directory for files without a PC filename extension like .doc .xls and then adds them. The reason for writing the...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
27
by: gmtonyhoyt | last post by:
I need assistance coming up with a clean way to handle filename extensions with my application. While I can come up with several ways of doing so on my own, I felt perhaps it would be worth...
3
by: Mullin Yu | last post by:
i've created a console application, and by default the filename will be my project/solution name, ie. testCmd.exe but, can i change it during the build/deployment process to testCmdNew.com ...
2
by: Csharper95 | last post by:
I want to get the file name and path from a SaveFileDialog (for a 'save as' operation) after the user has saved the information under a new file name (and presumably under a new path) ? I want...
10
by: Brian Gruber | last post by:
Hi, I'm looking for a way to rename a whole directory of files in short order. The files in the directory have different lengths, however all of them end with _xxxx the x's represent a randomly...
8
by: Lad | last post by:
Hello, what is a way to get the the extension of a filename from the path? E.g., on my XP windows the path can be C:\Pictures\MyDocs\test.txt and I would like to get the the extension of the...
3
by: gopal | last post by:
In the SaveFileDialog window, below we have two combo boxes 1.FileName - which lists all the files with specified extension given by us 2.Save as Type - which displays type of file extension...
3
by: Hamayun Khan | last post by:
I have Two asp pages addfiles.asp insert.asp addfiles.asp is used to browse the files which i want to upload to server. in IE both the pages run and the files uploads ok. There is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.