I would like to know how to change the name of the file from '001.txt' to 'Hong Gil-dong-001.txt' or 'Im Kkeok-jeong-001.txt' freely.

Asked 2 years ago, Updated 2 years ago, 79 views

I would like to know how to change the name of the file from '001.txt' to 'Hong Gil-dong-001.txt' or 'Im Kkeok-jeong-001.txt' freely.

When there is a file named 001.txt

When the character 'Hong Gil-dong' is input through the input command, it changes to the name 'Hong Gil-dong-001.txt'.

I want to make a program that changes to the name of Lim Kkeokjeong-001.txt when I receive the text 'Im Kkeokjeong'.

I know I have to use the name, but I don't know how to change it to a name I want at that time, not a fixed name.

rename file-name python

2022-09-20 22:11

1 Answers

import os

filename = '001.txt'
prefix = input()

os.rename(filename, prefix + '-' + filename)


2022-09-20 22:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.