Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut and Paste a File or Directory in Python [duplicate]

Tags:

python

I need to move a lot of data to different locations on one drive, so cutting and pasting would be much faster. Currently, I'm just using shutil.copytree and shutil.rmtree, which works but it's slow.

Is there any way to cut/paste files instead of copy/delete?

like image 518
Ryan Avatar asked Oct 18 '14 19:10

Ryan


People also ask

How do I copy the contents of a directory in Python?

The copy2() method in Python is used to copy the content of the source file to the destination file or directory. This method is identical to shutil. copy() method also preserving the file's metadata.

What is used to copy a image from one folder to another in Python?

To copy files, you can use shutil. copy() . To find all JPEG files in the source directory, you can use glob. iglob() .


1 Answers

shutil.move()

>>> import shutil
>>> shutil.move(source, destination)

os.rename()

>>> import os
>>> os.rename(source, destination)
like image 175
Adem Öztaş Avatar answered Sep 25 '22 02:09

Adem Öztaş