【原创】python实现清理本地缓存垃圾

2022-10-26 08:39:45
#coding=utf-8
import os
import glob
try:
        #利用glob模块定位需要清理垃圾的模糊路径
        File_1 = glob.glob("C:\Windows\SoftwareDistribution\DataStore\Logs\*.jrs")
        for log in File_1:
                if File_1 != 0:
                        try:
                                os.remove(log)
                                print "deleting redientsDataStore\Logs"
                        except OSError:
                                print "DataStore\Logs cant be removed"
        File_2 = glob.glob("C:\Windows\WinSxS\ManifestCache\*.*")
        for ManifestCache in File_2:
                if File_2 != 0:
                        try:
                                os.remove(ManifestCache)
                                print "deleting WinSxS\ManifestCache"
                        except OSError:
                                print "WinSxS\ManifestCache cant be removed"
        File_3 = glob.glob("C:\Windows\WinSxS\Backup\*.*")
        for Backup in File_3:
                if File_3 != 0:
                        try:
                                os.remove(Backup)
                                print "deleting WinSxS\Backup"
                        except OSError:
                                print "WinSxS\Backup cant be removed"
        File_4 = glob.glob("C:\ProgramData\Microsoft\Windows Defender\Definition Updates\Backup\*.*")
        for DefenderBackup in File_4:
                if File_4 != 0:
                        try:
                                os.remove(DefenderBackup)
                                print "deleting Definition Updates\Backup下Defender"
                        except OSError:
                                print "Definition Updates\Backup cant be removed"
        File_5 = glob.glob("C:\ProgramData\Microsoft\Windows Defender\Scans\*.*")
        for Scans in File_5:
                if File_5 != 0:
                        try:
                                os.remove(Scans)
                                print "deleting Windows Defender\Scans"
                        except OSError:
                                print "Windows Defender\Scans cant be removed"
        File_6 = glob.glob("C:\Users\*\*\Local\Temp\NVIDIA Corporation\NV_Cache\*.*")
        for NV_Cache in File_6:
                if File_6 != 0:
                        try:
                                os.remove(NV_Cache)
                                print "deleting NVIDIA Corporation\NV_Cache"
                        except OSError:
                                print "NVIDIA Corporation\NV_Cache cant be removed"
#        File_7=glob.glob("C:\Users\*\*\Local\Microsoft\Windows\Explorer\*.db")
#        for Explorer in File_7:
#                if File_7!=0:
#                        try:
#                                os.remove(Explorer)
#                                print "deleting Windows\Explorer"
#                        except OSError:
#                                print "Windows\Explorer cant be removed"
        File_8 = glob.glob("C:\Windows\Temp\*.*")
        for Temp in File_8:
                if File_8 != 0:
                        try:
                                os.remove(Temp)
                                print "deleting Windows\Temp"
                        except OSError:
                                print "Windows\Temp cant be removed"
        File_9 = glob.glob("C:\*\*\Local Settings\Temp\*.*")
        for SettingTemp in File_9:
                if File_9 != 0:
                        try:
                                os.remove(SettingTemp)
                                print "deleting Local Settings\Temp"
                        except OSError:
                                print "Local Settings\Temp cant be removed"
        File_10 = glob.glob("C:\*\*\Local\TaoBrowser\User Data\Default\Cache\*.*")
        for TaoBrowser in File_10:
                if File_10 != 0:
                        try:
                                os.remove(TaoBrowser)
                                print "deleting TaoBrowser\User Data\Default\Cache"
                        except OSError:
                                print "TaoBrowser\User Data\Default\Cache cant be removed"
finally:
                print "finally and enjoy"
raw_input()

转载于:https://www.cnblogs.com/huangxiaocheng/p/7597412.html

  • 作者:dfgdf213123
  • 原文链接:https://blog.csdn.net/dfgdf213123/article/details/101762428
    更新时间:2022-10-26 08:39:45