14.Clear The Clutter.py

# Write a problem to clear the clutter inside a folder on your computer.
# You should use OS module to rename all the png images from 1.png all the
# way till n.png where n is the number of png files in that folder.
# Do the same for other file formats.
# For example:
# sdfs.png --> 1.png
# sase.png --> 2.png
# ljkli.png --> 3.png

import os

files = os.listdir(r"D:\PYTHON B TO A\png files")
i = 1

for file in files:
if file.endswith(".png"):
print(file)
os.rename(
fr"D:\PYTHON B TO A\png files\{file}",
fr"D:\PYTHON B TO A\png files\{i}.png"
)

        i = i + 1 

Comments

Popular posts from this blog

3.FaulyCalculator.py

11.Snake Water Gun Game.py

15.PyStopWatch.py