Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I looked into the Python os interface but was unable to locate a method to move a file. How would I do the equivalent of $ mv ... in Python?

>>> source_files = '/PATH/TO/FOLDER/*'

>>> destination_folder = 'PATH/TO/FOLDER'

>>> # equivalent of $ mv source_files destination_folder

1 Answer

0 votes
by (106k points)
edited by

You can use os.rename() or shutil.move()for moving a file in Python

See the code below while both employ the same syntax:-

import os

import shutil 

os.rename("path/to/current/", "path/to/new/destination/for/") shutil.move("path/to/current/", "path/to/new/destination/for/") 

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Jun 26, 2019 in Python by Aarav (11.4k points)
+3 votes
2 answers
0 votes
2 answers
asked Aug 23, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
asked May 30, 2019 in Python by Ritik (3.5k points)
0 votes
1 answer

Browse Categories