Advertisement
Guest User

Untitled

a guest
Jun 10th, 2015
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import os, sys
  2.  
  3. def change_file_ext(cur_dir, old_ext, new_ext, sub_dirs=False):
  4.     if sub_dirs:
  5.         for root, dirs, files in os.walk(cur_dir):
  6.             for filename in files:
  7.                 file_ext = os.path.splitext(filename)[1]
  8.                 if old_ext == file_ext:
  9.                     oldname = os.path.join(root, filename)
  10.                     newname = oldname.replace(old_ext, new_ext)
  11.                     os.rename(oldname, newname)
  12.     else:
  13.         files = os.listdir(cur_dir)
  14.         for filename in files:
  15.             file_ext = os.path.splitext(filename)[1]
  16.             if old_ext == file_ext:
  17.                 newfile = filename.replace(old_ext, new_ext)
  18.                 os.rename(filename, newfile)
  19.  
  20.  
  21. path = "-YOUR FILE PATH-"
  22. # print os.listdir(path)
  23. old_ext = ".SDIR"
  24. new_ext = ".wav"
  25. change_file_ext(path, old_ext, new_ext, True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement