我做错了什么 我需要改进什么?
import os
source = "C:\\Users\\User\\Desktop\\ala.txt"
destination = "C:\\Users\\User\\Desktop\\zzz.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")
最佳答案
您可以尝试导入shutil并调用 Shutil.move(源,目的地)。 Shutil 模块提供 move 文件以及整个文件夹的功能。
关于python - 如何在python中将文件从文件夹A move 到文件夹B?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69604003/