Depth study of the picture there is often a batch rename, sort data from the Internet to see what the future for easy viewing.
Import OS class BatchRename (): '' ' batch rename folder picture file ' '' DEF the __init__ (Self): self.path = ' C: / the Users / JingPan / Desktop / data_json ' # represents treatment needs to be named folder DEF the rename (Self): Filelist = the os.listdir (self.path) # acquires the file path TOTAL_NUM = len (Filelist) # Get file length (number) I = 1 # represents a file name starting from 1 for Item in Filelist: IF item.endswith ( ' .json ' ): # Original picture format is jpg format (or the source file is png format and other formats, the latter format can be converted to a format adjusted to their needs) src = os.path.join (os.path.abspath ( self.path), Item) # DST = the os.path.join (os.path.abspath with (self.path), '' + STR (I) + '.jpg') # format is also processed, jpg Of course this can be changed png format DST = the os.path.join (os.path.abspath with (self.path), ' 000 ' + the format (STR (I), ' 0> 3S ' ) + ' .json ' ) # naming format in this case is 000000.jpg form the desired format autonomously define the try : os.rename (the src, DST) Print ( ' Converting% to S% S ... ' % (src, dst)) i = i + 1 except: continue print ('total %d to rename & converted %d jpgs' % (total_num, i)) if __name__ == '__main__': demo = BatchRename() demo.rename()
Results are as follows: