python 將文件移入回收站
python如果要刪除一個文件,通常使用
os.remove(filename)
但是這樣就直接從磁盤刪除了。
有些文件需要刪除到回收站,以便誤刪后還能找回文件
from win32com.shell import shell,shellcon debug=False def deltorecyclebin(filename): print('deltorecyclebin', filename) # os.remove(filename) #直接刪除文件,不經過回收站 if not debug: res= shell.SHFileOperation((0,shellcon.FO_DELETE,filename,None, shellcon.FOF_SILENT | shellcon.FOF_ALLOWUNDO | shellcon.FOF_NOCONFIRMATION,None,None)) #刪除文件到回收站 if not res[1]: os.system('del '+filename)
安裝模塊
pip install pywin32
假如安裝后報錯,顯示import win32file ImportError: DLL load failed
【解決方案】
從定位上看是pywin32這個庫出現了問題,用conda list查看pywin32 顯示的版本是223
他說要把pywin32降級到224。
pip install pywin32==224
在安裝過程中發現,在我的環境中pywin32實際上是227,不是conda list中顯示的223。
安裝224版本之后,問題解決。
參考了這個博主的解決辦法http://www.rzrgm.cn/longweiqiang/p/13086491.html

浙公網安備 33010602011771號