Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Edit Filename
#7
@snippsat and @michael1789

This os.rename does not seem to work, would you know a solution to these problems?

import os
 
path = 'C:/Users/Name/Downloads/Test'

for i in range(ord('a'), ord('f')+1):
    os.rename(r'{path}ppl15{chr(i)}.png', r'{path}ppl139.{i}.png')
 
print('Finish')

I got a solution. I'll post, if anyone can improve, post here too. Thank you! My first contact with the community was very productive. Python is the future.

import os

for i in range(ord('a'), ord('f')+1):
    os.rename(r'C:/Users/Name/Downloads/Teste/'+'ppl15'+ chr(i)+'.'+'png', 'C:/Users/Name/Downloads/Teste/'+'ppl139'+'.'+str(i-96)+'.'+'png')

print('Finish')
Reply


Messages In This Thread
Edit Filename - by arthur_cti - Dec-06-2019, 03:53 AM
RE: Edit Filename - by michael1789 - Dec-06-2019, 04:12 AM
RE: Edit Filename - by arthur_cti - Dec-06-2019, 04:48 AM
RE: Edit Filename - by michael1789 - Dec-06-2019, 04:57 AM
RE: Edit Filename - by snippsat - Dec-06-2019, 06:05 AM
RE: Edit Filename - by michael1789 - Dec-06-2019, 06:36 AM
RE: Edit Filename - by arthur_cti - Dec-06-2019, 10:31 PM
RE: Edit Filename - by snippsat - Dec-06-2019, 11:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020