我正在尝试使用send2trash将一个文件发送到垃圾中。使用像send2trash("C:\\path\\to\\file\\file.txt")
一样正确,但当使用filedialog.askopenfilename()
并将结果输入到它时,没有效果。我尝试过使用str()
,但没有效果。
代码:
m = filedialog.askopenfilename(title="Choose which file to shred",filetypes=[("file","*.*")])
send2trash(m) #Also used send2trash(str(m)) but that did not work
错误:
File "c:\Python310\Scripts\delete.py", line 293, in <module>
send2trash(str(m))
File "C:\Python310\lib\site-packages\send2trash\plat_win_legacy.py", line 115, in send2trash
File "C:\Python310\lib\site-packages\send2trash\plat_win_legacy.py", line 115, in <listcomp>
paths = [get_short_path_name(path) for path in paths]
File "C:\Python310\lib\site-packages\send2trash\plat_win_legacy.py", line 99, in get_short_path_name
raise WindowsError(err_no, FormatError(err_no), long_path)
FileNotFoundError: [Errno 2] The system cannot find the file specified.: '\\\\?\\C:/Python310/Scripts/testfile.txt'
我不知道为什么这不管用,所以任何帮助都是非常感谢的。
Python 3.10.4,Windows 10
发布于 2022-05-26 12:51:14
对于python来说非常新,但我认为send2trash只接受路径名中的反斜杠,并且查看使用正斜杠返回路径'askopenfilename‘的错误。
m = filedialog.askopenfilename(title="Choose which file to shred",filetypes=[("file","*.*")])
m = m.replace('/', '\\')
send2trash(m)
https://stackoverflow.com/questions/72155221
复制相似问题