Rename and move file with Python [duplicate]

Yes you can do this. In Python you can use the move function in shutil library to achieve this.

Let’s say on Linux, you have a file in /home/user/Downloads folder named “test.txt” and you want to move it to /home/user/Documents and also change the name to “useful_name.txt”. You can do both things in the same line of code:

import shutil

shutil.move('/home/user/Downloads/test.txt', '/home/user/Documents/useful_name.txt')

In your case you can do this:

import shutil

shutil.move('oldname', 'renamedfiles/newname')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)