【问题标题】:Delete Temp Files and Empty Recycle Bin_Python 3?删除临时文件并清空回收站 Python3?
【发布时间】:2018-10-05 12:32:55
【问题描述】:

想知道是否有人可以帮助批评我整理的这段代码。

假设删除所有临时文件和文件夹,然后清空回收站。

由于使用 Pyinstaller,我不得不进行一些调整,并且我希望控制台保持打开状态并让用户在阅读后继续。

import os
file_size = os.path.getsize('C:\Windows\Temp')
print(str(file_size) + "kb of data will be removed")
import os, subprocess
del_dir = r'c:\windows\temp'
pObj = subprocess.Popen('rmdir /S /Q %s' % del_dir, shell=True, stdout = 
subprocess.PIPE, stderr= subprocess.PIPE)
rTup = pObj.communicate()
rCod = pObj.returncode
if rCod == 0:
    print('Success: Cleaned Windows Temp Folder')
else:
    print('Fail: Unable to Clean Windows Temp Folder')
import winshell
winshell.recycle_bin().empty(confirm=False, show_progress=False, 
sound=False)
from random import randint
from time import sleep
sleep(randint(4,6))
input("Press any key to continue")

【问题讨论】:

标签: python python-3.x popen


【解决方案1】:

您应该看看标准库中的以下模块:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多