Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Edit Filename
#8
It's not r but f i use string formatting f-string.
Test working.
import os

path = 'C:/Users/Name/Downloads/'
os.chdir(path)
for i in range(ord('a'), ord('c')+1):
    os.rename(f'{path}ppl15{chr(i)}.png', f'{path}ppl139.{i}.png')
print('Finish')
These filename most exists in path Download.
ppl15a.png
ppl15b.png
ppl15c.png
My output:
Output:
ppl139.97.png ppl139.98.png ppl139.99.png
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