The answer of the "old school" was to use os.system . I am not familiar with Windows, but something like this will do the trick:
import os os.system('ren *.txt *.bat')
Or (maybe)
import os os.system('cmd /c ren *.txt *.bat')
But now, as Ashvini Chodhari noted, the "recommended" replacement is os.system subprocess.call
If REN is an internal Windows shell command:
import subprocess subprocess.call('ren *.txt *.bat', shell=True)
If this is an external command:
import subprocess subprocess.call('ren *.txt *.bat')
source share