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(file)[1] == format: # splitext() function splits a file into its name and its extension
os.rename(file, f"{i}.{format}")
i += 1
fpath = r"D:\abdur codes\space\thisisit\fffffffffffffffff"
filename = r"D:\abdur codes\space\thisisit\fffffffffffffffff\nothis.txt"
format = ".png"
soldier(fpath, filename, format)
################# The End ###########################
Comments
Post a Comment
Write something to CodeWithAbdur!