Hello everyone, I have a directory with 40 files.
File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the last prefix.
I even managed to insert the csv extension at the end of the file. but renaming files based on various prefixes is the tricky one. Can anybody help me. I will be posting the image of the code that was created.
Thanks.
/*
This code inserts the csv extension in the filename.
*/
path ="/dbfs/tmp/data/dadosjuridicos/descompactados"
for i in os.listdir(path):
files = os.path.join(path,i)
split= os.path.splitext(files)
if split[1]=='.COMPANY':
os.rename(files,split[0]+'COMPANY.csv')
if split[1]=='.ESTABLISHMENT':
os.rename(files,split[0]+'ESTABLISHMENT.csv')
if split[1]=='.PARTNER':
os.rename(files,split[0]+'PARTNER.csv')