#!/usr/bin/env python################################################################################### script function: rename files in a folder# # rel. date: 10/2015# Dr. Rene Cejas Bolecek# Low Temperatures Laboratory, CAB, Argentina.# email: reneczechdev@gmail.com# licence: MIT. http://opensource.org/licenses/MIT ##################################################################################importglobimportshutilrex='*.dat*'# Define regular expresion to get the files, not sorted!files=glob.glob(rex)#files.sort() # sort the list#print files # check sorted listnewFilename='10_id_'# new filenameforfinfiles:# loop over the listoriginalFilename=fy=f.split('.dat')# Reuse some strings from the original filename #print y[1] # just to checkintVal=int(y[1])#transform to integershutil.move(f,newFilename+"%d"%(2*intVal+1)+".dat")#rename fn #Old filename list:# {150830_iman18_10_20KTo100K_2mmHg.dat0, ..., 150830_iman18_10_20KTo100K_2mmHg.dat40}#New filename list:# {10_id_1.dat, ... , 10_id_81.dat}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.