0
How to change files names randomly?
I have folder contain images , I want to put them in new folder then loop through them to: -generate a random name from the English letters -rename the images inside the 'new folder' directory to the generated one
6 Antworten
+ 3
You can do it all with the os module learn it
https://docs.python.org/3/library/os.html
You will need os.path, os.mkdirs, os.cwd, and some checking
or post you attempts someone may help you with it
+ 1
# i guess this method will do:
c = 4 # number of tries if file exist
for i in (list of names in directory):
tmp = random name.png # or whatever
while c: # so if c == 0, then loop stops
add file as `i[0]+tmp[1:]`.png
c-=1
0
Eh tricky ...
you can use:
1- os.system() and random to send commands to shell, or;
2- Ion Kare 's answer can be used as general.
0
Ion Kare Ervis Meta - SoloHelper
Here is my try on visual code so don't run it
https://code.sololearn.com/cpDNazVWuxDp/?ref=app
0
That looks alright.
0
Ervis Meta - SoloHelper
It worked with me but had a little problem :
It working on some files then stop because name been exist in folder so os.rename stop
I want to make it looping if created file name 'u' then found it then pass and creates name 'uv' or 'uZ' or whatever