我正在尝试使用shutil库将文件移动到回收站。以下是相关代码行,但我遇到了奇怪的错误。这两个文件都在本地,并且我可以在我的电脑上访问这两个位置。为什么会出现这个错误?因为我从F:运行Main.py吗?
import shutil
# Path to folder where files should be trashed
dump_folder = r"C:\$Recycle.Bin\\"
file_name = "C:\\Storage\\\\statuti.docx"
# Move it to storage directory
shutil.move(file_name, dump_folder)
错误消息
F:\Python\Project\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2020.1\plugins\python-ce\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 54648 --file F:\Python\Main.py 连接到 pydev 调试器 (构建 203.5981.165) Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 788, in move os.rename(src, real_dst) PermissionError: [WinError 5] 拒绝访问。: 'C:\Storage\\statuti.docx' -> 'C:\Recycle.Bin\\'
在处理以上异常时,发生了另一个异常:
Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 261, in copyfile with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: OSError: [Errno 22] 参数无效: 'C:\Recycle.Bin\\'