Clean you folder with os module pretty folder exercise

technical talkiess
0

 Pretty folder:



import os




def prettyFolder(dir):

    i = 1

    for item in dir :

        if os.path.isfile(item):

            split_tup = os.path.splitext(item)

            ext = ['.jpg','.JPG','.png','.PNG','.JPEG','.jpeg','.gif','.GIF']

            if split_tup[1] in ext:

                os.rename(item,str(i)+split_tup[1])

                i = i+1

                print(i)

            else:

                os.rename(item,item.capitalize())

        else:

            print("Test")


   





prettyFolder(os.listdir())




# print(os.listdir())



Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)