removing extension

wilson wilson.t.thompson at gmail.com
Sun Apr 27 12:34:02 CEST 2008


i was trying to convert all images in a folder to another type and
save the new images in a separate folder.for that i wrote a class and
coded some part

class ConvertImgs:
	def __init__(self,infldr,outfldr):
		if os.path.isdir(infldr):
			self.infldr=infldr
			self.outfldr=outfldr
		else:
			print "no such folder,exits program"
			exit(1)
		if not os.path.isdir(self.outfldr):
			os.mkdir(self.outfldr)
			print "made:",self.outfldr

		for x in os.listdir(infldr):
self.origlist=[os.path.normpath(os.path.join(self.infldr,x)) for x in
os.listdir(infldr)]

...
the self.origlist  returns a list of filenames in infolder.I would
like to get them as 'C:\\myimages\\imageone'  instead of 'C:\\myimages\
\imageone.jpg' sothat i can add a diff extension to all those strings
in the list and save in diff format(ie change 'C:\\myimages\\imageone'
to 'C:\\myimages\\imageone.gif ' and save in gif format).but i don't
know how to remove those extension from the namestring ..can someone
help?
W



More information about the Python-list mailing list