找回密码
 加入
搜索
查看: 3095|回复: 12

删除系统补丁备份目录

[复制链接]
发表于 2009-4-26 13:26:59 | 显示全部楼层 |阅读模式
本帖最后由 hooshen 于 2009-4-30 14:56 编辑

删除系统补丁备份文件的脚本求教各位大侠
我用批处理是这样写的
echo 正在删除Windows补丁备份目录,请稍等......
REM 删除$hf_mig$文件夹
RD %windir%\$hf_mig$ /Q /S
REM 把补丁卸载文件夹的名字保存成hotfix.txt
dir %windir%\$NtUninstall* /a:d /b >%windir%\hotfix.txt
REM 从hotfix.txt中读取文件夹列表并且删除文件夹
for /f %%i in (%windir%\hotfix.txt) do rd %windir%\%%i /s /q
REM 删除hotfix.txt
del %windir%\hotfix.txt /f /q
echo 正在删除补丁安装记录,请稍等......
del /f /s /q %systemdrive%\KB*.log
改用AU3写,其中删除$NtUninstall*文件夹,这条就不会写了,
 楼主| 发表于 2009-4-26 13:51:36 | 显示全部楼层
RunWait(@comspec & " /c dir %windir%\$NtUninstall* /a:d /b >%windir%\hotfix.ini","",@sw_hide)
$var = IniReadSectionNames(@WindowsDir & "\hotfix.ini")
For $i = 1 To $var[0]
        Next
DirRemove(@WindowsDir &$var,1)

请教各位大侠,这段代码为什么不起作用啊
发表于 2009-4-26 14:29:58 | 显示全部楼层
$aKBFile = _FileListToArray(@WindowsDir, "$NtUninstallKB*", 2)
        For $i = 1 To $aKBFile[0]
                If NOT StringRegExp($aKBFile[$i], "^\$NtUninstallKB\d{6}(\-v\d+)?\$$") Then ContinueLoop
                DirRemove(@WindowsDir & "\" & $aKBFile[$i], 1)
        Next
 楼主| 发表于 2009-4-27 16:06:43 | 显示全部楼层
D:\1.bmp
大侠,第一行不行啊
我改成:
$aKBFile = _FileListToArray(@WindowsDir & "\$NtUninstall*", 1)
也不行,
不知为什么,请赐教!
 楼主| 发表于 2009-4-27 16:09:36 | 显示全部楼层
Line 30  (File "D:\清理备份\删除系统补丁备份目录.au3"):

$aKBFile = _FileListToArray(@WindowsDir, "$NtUninstallKB*", 2)
$aKBFile = ^ ERROR

错误:  未知函数名.
发表于 2009-4-27 16:20:54 | 显示全部楼层
#Include <File.au3>
 楼主| 发表于 2009-4-27 16:38:35 | 显示全部楼层
#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray(@WindowsDir,"$NtUninstallKB*")
       For $i = 1 To $FileList[0]
                If NOT StringRegExp($FileList[$i], "^\$NtUninstallKB\d{6}(\-v\d+)?\$$") Then ContinueLoop
                DirRemove(@WindowsDir & "\" & $FileList[$i], 1)
        Next
这样写会有三个文件夹不能删除:
$NtUninstallKB936782_WMP10$
$NtUninstallKB952069_WM9$
$NtUninstallKB957097_0$
为什么呢?
发表于 2009-4-28 00:24:21 | 显示全部楼层
7# hooshen


我用了正则。你把If NOT StringRegExp那行去掉吧。
发表于 2009-4-28 00:36:00 | 显示全部楼层
或者我改了下正则:
        $aKBFile = _MyFileListToArray(@WindowsDir, "$NtUninstallKB*", 2)
        For $i = 1 To $aKBFile[0]
                If StringRegExp($aKBFile[$i], "^\$NtUninstallKB\d{6}([-_]\w+)?\$$") Then _
                DirRemove(@WindowsDir & "\" & $aKBFile[$i], 1)
        Next
 楼主| 发表于 2009-4-30 11:53:21 | 显示全部楼层
谢谢sensel提供的帮助,问题已解决
修正后的代码如下
;删除Windows补丁备份目录
#Include <File.au3>
DirRemove(@WindowsDir & "\$hf_mig$", 1)
If FileExists(@WindowsDir & "\$NtUninstallKB*") Then
        ToolTip(@CR&""&"  系统目录存在补丁备份文件,1秒钟后将自动删除  "&""&@CR,@DesktopWidth-460,@DesktopHeight-100)
        Sleep(1000)
        $FileList=_FileListToArray(@WindowsDir,"$NtUninstallKB*")
               For $i = 1 To $FileList[0]
                        DirRemove(@WindowsDir & "\" & $FileList[$i], 1)
               Next
Else
        ToolTip(@CR&""&"  系统目录没有补丁备份文件,1秒钟后将自动退出  "&""&@CR,@DesktopWidth-460,@DesktopHeight-100)
        Sleep(1000)
EndIf
发表于 2009-4-30 22:03:45 | 显示全部楼层
多谢,也在找这个解决办法。
发表于 2009-10-8 13:15:51 | 显示全部楼层
谢谢了。。
发表于 2012-6-16 18:48:28 | 显示全部楼层
谢谢了。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-30 07:23 , Processed in 0.077944 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表