import os
def dosya_uzantilarini_degistir(cur_dir, old_ext, new_ext, sub_dirs=False):
if sub_dirs:
for root, dirs, files in os.walk(cur_dir):
for dosya in files:
file_ext = os.path.splitext(dosya)[1]
if old_ext == file_ext:
oldname = os.path.join(root, dosya)
newname = oldname.replace(old_ext, new_ext)
os.rename(oldname, newname)
else:
files = os.listdir(cur_dir)
for dosya in files:
file_ext = os.path.splitext(dosya)[1]
if old_ext == file_ext:
newfile = dosya.replace(old_ext, new_ext)
os.rename(dosya, newfile)
dosya_uzantilarini_degistir('/home/user/klasorlerim', '.txt', '.html')
dosya_uzantilarini_degistir('/home/user/klasorlerim', '.txt', '.html', True) dosya uzantilarini degistir html yi txt yap yada tersi
0
●1.258
- 26-08-2012, 20:25:34