Last active
October 13, 2015 18:38
-
-
Save renexdev/54fbdccca6ba0568c3e1 to your computer and use it in GitHub Desktop.
rename files in a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
################################################################################## | |
import glob | |
import shutil | |
rex = '*.dat*' # Define regular expresion to get the files, not sorted! | |
files = glob.glob(rex) | |
#files.sort() # sort the list | |
#print files # check sorted list | |
newFilename = '10_id_' # new filename | |
for f in files: # loop over the list | |
originalFilename = f | |
y = f.split('.dat') # Reuse some strings from the original filename | |
#print y[1] # just to check | |
intVal = int(y[1]) #transform to integer | |
shutil.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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment