Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python increment filename by 1

import glob
import re
import os


def main():
    # We want all files that are S00E0x
	for name in glob.glob('./*S0*'):
        # We want to find in the filename 'Exx' and increase xx by 1
		new_name = re.sub('(E)([0-9]{2})', increment, name)
		os.rename(name, new_name)


def increment(num):
    # Return the first match which is 'E'. Return the 2nd match + 1 which is 'x + 1'
	return num.group(1) + str(int(num.group(2)) + 1).zfill(2)


if __name__ == '__main__':
	main()
Comment

PREVIOUS NEXT
Code Example
Python :: python regex validate phone number 
Python :: python count of values in array 
Python :: python linux script 
Python :: python split by list 
Python :: convert number to reversed array of digits python 
Python :: pandas grid subplots 
Python :: how to append data in excel using python 
Python :: run python script without .py 
Python :: Solve linear equation with np.linalg.solve 
Python :: python gui kivvy 
Python :: Access the elements using the [] syntax nested dictionary 
Python :: TfidfVectorizer use 
Python :: run julia in p;ython 
Python :: flip dictionary python 
Python :: symmetrical sum python 
Python :: python replace string with int in list 
Python :: add colorbar matplotlib 
Python :: python linux command 
Python :: k fold CV with xgboost 
Python :: chrome detach selenium python 
Python :: how to stop auto log writing by other function in python 
Python :: for loop in python array 
Python :: python write list to file with newlines 
Python :: split column and rename them 
Python :: unpacking in python 
Python :: how to change the main diagonal in pandas 
Python :: # logging 
Python :: get value of bit in integer python 
Python :: humanname python 
Python :: iterate rows and columns dataframe 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =