python - Rename list files cannot find files -


i'm trying rename files replacing out commas. have function finds errors , passes function on button click. second example obvious, believe os.rename in first example taken again. doing wrong?

            if self.filenames:                     print self.dirname  ## finds directory                     path = self.dirname                     dirlist=os.listdir(path)                                             self.filename in dirlist:                             print self.dirname ## finds directory                             f = self.filename                             print f ## finds c,1.txt !!!                             if not f.startswith('.') , f.find(',') >= 0:                                     os.rename(f, f.replace(',','')) 

traceback: c,1.txt system cannot find file specified

            if self.filenames:                     print self.dirname ## finds directory                                             self.filename in os.listdir("."):                             print self.dirname ## finds directory                             f = self.filename                             print f                             if not f.startswith('.') , f.find(',') >= 0:                                     os.rename(f, f.replace(',','')) 

replaces files in working directory

i think should change os.rename(f, f.replace(',','')) os.rename(os.path.join(self.dirname, f), os.path.join(self.dirname, f.replace(',',''))). rename function expects valid path file, , need concatenate base directory path filename if file not in current directory.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -