Created
November 25, 2015 09:25
-
-
Save gmastrokostas/31a794fc24c32f7cd5b0 to your computer and use it in GitHub Desktop.
Python – Search for specific types of files and rename the files or part of the files
This file contains hidden or 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
| import os | |
| import re | |
| src_drct='/home/gmastrokostas/tmp' | |
| for files in os.listdir(src_drct): | |
| if files.endswith('.txt'): #Select all files with the .txt ext | |
| oldF = os.path.join(src_drct, files) #Join full path with files found | |
| midF = re.split(r'\_', files) #split files that contain underscore | |
| newF = oldF.replace('_01012015', '_01012014') #create the replacement var | |
| out = os.rename(oldF, newF) #start renaming. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment