Answers for "how to move file in python using os"

21

python move file

# To move a file in Python, use one of the following:
import os
import shutil

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

# In the first two cases the directory in which the new file
# is being created must already exist.
Posted by: Guest on March-10-2020
0

move files in python

import shutil
original = r'original path where the file is currently stored\file name.file extension'
target = r'target path where the file will be moved\file name.file extension'
shutil.move(original,target)
Posted by: Guest on September-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language