mardi 20 août 2019

add random number to multi fillenames

i have a folder: "songs" inside i have filles "song1singer1.txt", "song2singer2.txt"... -i want put a random number with 3 digits before fillename like: "145_song1singer1.txt","008_song2singer2.txt","049_song3singer3.txt"... and the next time i can use the same or other program and change the random number with another random number like: "872_song1singer1.txt","263_song2singer2.txt","492_song3singer3.txt"

thank you for your attention!

i am new in programming and start from Python3 (i use linux)

import os

def renamer(folder):
    dirname = folder
    files = os.listdir(folder)
    os.chdir(folder)
    for i in files:
        os.rename(i, dirname + '_' + i)

#import random
#print(random.randint(0,9))

renamer('testrename')




Aucun commentaire:

Enregistrer un commentaire