Change the filename extension of multiple files in a directory.( e.g change all .html to .php )
-
Place "extensions.py" file inside the directory where you want to change file extensions.
-
Open your terminal, execute a command that should look like this :
python extensions.py oldExtension newExtension
Where oldExtension should be the file extension you wanna change (html,php ...) for all files in that directory. And newExtension is the extenstion you wanna change oldExtension to.
##Examples In your terminal :
python extensions.py html php
Sir actually there is an exception will occur in most of the linux distribution systems, From my experience. I put the actual code here.
import os
import sys
import glob
#author Athul A
path = "File name"
def change(old_ext,new_ext):
[ os.rename( f,"%s.%s" % (os.path.splitext(f)[0],new_ext) ) for f in glob.iglob(path + "/**/*." + old_ext) ]
optional Section
if name == "main":
if len(sys.argv) > 2:
change(sys.argv[1],sys.argv[2])
OR you can directly put the following commands
change(old_ex,new_ex)