想知道是否有人能帮我批评一下我写的代码。在
假设删除所有临时文件和文件夹,然后清空回收站。在
我不得不做一些调整,因为使用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")
您应该看看标准库中的以下模块:
在文件系统上提供高级操作的
shutil
(删除树等)。 https://docs.python.org/3.6/library/shutil.html#module-shutiltempfile
对临时文件提供了更好的处理。https://docs.python.org/3.6/library/tempfile.html#module-tempfileatexit
提供在退出Python解释器之前执行的函数的注册表,无论原因是什么。https://docs.python.org/3.6/library/atexit.html?highlight=atexit#module-atexit相关问题 更多 >
编程相关推荐