Monica Monica - 1 year ago 75
Python Question

Renaming files with two different extension

I'd like to rename files in the current directory with the *.inp and *out extensions

#!/usr/bin/env python
import glob
import os

for namefile in glob.glob('*.inp'):
new_namefile = namefile.replace('dim', 'mon')

os.rename(namefile, new_namefile)

How can I rename files *.inp and *.out at the same time?

Answer Source
from glob import glob
for namefile in glob('*.inp')+glob('*.out'):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download