Python move replace file tutorial example explained
#python #move #replace #file
import os
source = "C:\\Users\\User\\Desktop\\source.txt"
destination = "C:\\Users\\User\\Desktop\\destination.txt"
try:
if os.path.exists(destination):
print("There is already a file there")
else:
os.replace(source,destination)
print(source+" was moved")
except FileNotFoundError:
print(source+" was not found")
Bro Code merch store: https://teespring.com/stores/bro-code-5
#python #move #replace #file
import os
source = "C:\\Users\\User\\Desktop\\source.txt"
destination = "C:\\Users\\User\\Desktop\\destination.txt"
try:
if os.path.exists(destination):
print("There is already a file there")
else:
os.replace(source,destination)
print(source+" was moved")
except FileNotFoundError:
print(source+" was not found")
Bro Code merch store: https://teespring.com/stores/bro-code-5
- Category
- Bro Code
- Tags
- python move files, python move file, move a file in python
Be the first to comment


