Friday, November 15, 2013

Batch renaming of files containing some character in theirs name

import glob
import os
os.chdir("C:\Users\waldekd\Desktop\PHOTOGRAPHY")
for files in glob.glob("*.*"):
    if not files.endswith("mp3"):
        index = files.find("@")
        if index > -1:
             print files[:index]
             os.rename(files, 'new'.join(files[:index]))

No comments:

Search This Blog