473,387 Members | 1,745 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.

change file extension

I'm a newbie so please excuse my ingnorance. I have serveral hunderd files in a folder and need to change the file extension from '.pnt' to '.txt'. Any suggestions?

Thanks
Mar 6 '07 #1
4 33391
ilikepython
844 Expert 512MB
I'm a newbie so please excuse my ingnorance. I have serveral hunderd files in a folder and need to change the file extension from '.pnt' to '.txt'. Any suggestions?

Thanks

Ok, I'm not exactly sure about this but I think you have to use the 'os' module somehow like this:
Expand|Select|Wrap|Line Numbers
  1. files = os.listdir(os.curdir)
  2. for file in files:
  3.     if '.pnt' in file:
  4.         newfile = file.replace('.pnt', '.txt')
  5.         os.rename(file, newfile)
  6.  
not exactly sure though.
Mar 6 '07 #2
ghostdog74
511 Expert 256MB
another way
Expand|Select|Wrap|Line Numbers
  1. import os,glob
  2. os.chdir(dir)
  3. for fi in glob.glob("*.pnt"):
  4.    os.rename(fi, fi[:-3] + "txt")     
  5.  
Mar 7 '07 #3
Expand|Select|Wrap|Line Numbers
  1. os.chdir(value)
  2. for aFile in glob.glob("*.php"):
  3.     base = os.path.splitext(aFile)[0]
  4. os.rename(aFile, base + ".null")
  5.  
Apr 11 '15 #4
dwblas
626 Expert 512MB
Note that you should not use "file" as a variable name. It over-writes Python's built in function with the same name https://docs.python.org/2/library/functions.html#file
Apr 13 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: b.milbrandt | last post by:
I am trying to convert a unix shell script to perl, and I have having a problem with the portion that copies files based on extension and renaming them in the process. I only trying to copy files...
5
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
1
by: Nicky | last post by:
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
4
jamesd0142
by: jamesd0142 | last post by:
Ok here's one for the experts... I want to create a text file "test.text" that stores different values on each line. Is it possible for me to go to the directory its saved and change the...
1
by: sandysharma | last post by:
how to write a script(batch file or dat file ) to change extension of files from .RPT to .html actually I also want to ftp file first form the unix server to the window ...
3
by: adamjblakey | last post by:
Hi, I want to convert this into a function. How would i go about doing this? $path_thumbs = "images/thumbs"; $path_big = "images/big"; //the new width of the resized image....
1
by: Pekeika | last post by:
Python 2.5 doesn't support/load .dll anymore. Is PythonWin 2.5 the same case? If a .DLL file is not loading, should I change its extension for it to work? What extensions should be now, .pyo,...
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.