Nov-15-2018, 03:40 PM
Im trying to rename only the first 4 characters of a filename.
Example: rename a045av18.c00 to paav18.c00
The "av18" will change each day so i just want to replace "a045" with "pa" and thats it.
Having a hard time getting this to work. I tried a rename with DOS commands but it doesnt work with a wildcard.
Example: rename a045av18.c00 to paav18.c00
The "av18" will change each day so i just want to replace "a045" with "pa" and thats it.
Having a hard time getting this to work. I tried a rename with DOS commands but it doesnt work with a wildcard.
import os
import sys
import re
if __name__ == "__main__":
_, indir = sys.argv
infiles = [f for f in os.listdir(indir) if os.path.isfile(os.path.join(indir
for infile in infiles:
outfile = re.sub(r'pa', r'a045' , infile)
os.rename(os.path.join(indir, infile), os.path.join(indir, outfile))
