In the folder C:\Users\Administrator\Downloads\T
000230_2022-07-14_05-02-44.png,
000140_2022-07-14_12-43-38.png,
000105_2022-07-14_12-54-49.png,
There are these files. 6 digits in front of the file
000230.png
000140.png I want to change it like this.
I'm trying to look it up, but I'm too new to understand.
How do I approach to delete without the extension after leaving only the first six digits?
import os
path = 'C:/Users/Administrator/Downloads/T'
for file in os.listdir(path):
if filename.startswith("[0:5]"):
os.rename(filename,"[0:5]"+filename[-5:])
import os
path = 'C:/Users/Administrator/Downloads/T'
for filename in os.listdir(path):
name = filename.rsplit(".", 1)[0][0:6]
ext = filename.rsplit(".", 1)[1]
os.rename(filename, name+ext)
Why don't you try this?
© 2024 OneMinuteCode. All rights reserved.