Posts

Showing posts with the label python programming

Working with OS module in Python

import os def soldier(a,b,c): os.chdir(a) i = 1 items = os.listdir(a) for item in items: if item.endswith(b): os.rename(item, item.capitalize()) if item.endswith(c): os.rename(item, f"{i}.{c}") i += 1 fpath = r"D:\abdur codes\space\thisisit\fffffffffffffffff" filename = ".py" format = ".png" soldier(fpath, filename, format) ###################################################################### import os def soldier(fpath, filename, format): os.chdir(fpath) i = 1 files = os.listdir(fpath) with open(filename) as f: # this file contains files names which we will not tamper with filelist = f.read().split("\n") for file in files: if file not in filelist: os.rename(file, file.capitalize()) # if os.splitext(fpath)[1]==format: if os.path.splitext(fil