How to automatically change the symbol in the file name with the using the range?

import os
import wget
import time
url = input("Enter the URL address that you need back apiti\n")
os.makedirs('C:/NewBackUp') 
while True:
 print("====================\nachalas load file...")
 wget.download(url, 'C:/NewBackUp')
 print("\Pfeil installed in C:/NewBackUp")
 print("\bledowa load in 3 seconds\n====================")
 time.sleep(3)

Need to change the name of the downloaded file every time 1 2 3 4 5 6 and so on up to 500 for example
without touching the file extension ie everything after the dot, for example there is file file.png need the name changed on 1.png then 2.png
But, may be this .exe so you need to change only to the point name
April 4th 20 at 13:17
2 answers
April 4th 20 at 13:19
>>> import os
>>> base=os.path.basename('/path/file.ext')
>>> base
'file.ext'
>>> os.path.splitext(base)
('file', '.ext')
>>> os.path.splitext(base)[0]
'file'
>>> # need a function and replace union with ext
So where does everything go? <_> It is possible please in my code to embed? - vivian62 commented on April 4th 20 at 13:22
# get a old name 
filename = wget.download(url, 'C:/NewBackUp')
# your function a
replcae_file(filename, new_name)
- Krystina_Runolfsdottir59 commented on April 4th 20 at 13:25
@vivian62for auto-number files, you can use regexp, like this (in this case suggests the presence of a file extension)

import re

filename = 'asd.33.lk3.3s23120b.jpg'

m = re.match("(.+?)(\d+)?(\.[^\.]+)$", filename)
if m:
 new_name = f"{m.group(1)}{int((m.group(2)) if m.group(2) else 0)+1}{m.group(3)}"
 print(new_name)
- Lauren commented on April 4th 20 at 13:28
April 4th 20 at 13:21
Read about the creation of cycles by using the range and the string formatting

Find more questions by tags Python