关于清理垃圾带进度条问题请教[已解决]
本帖最后由 m765555 于 2011-5-26 10:00 编辑想写个带进度条的垃圾清理工具,因个人能力有限,需要各位兄弟指点一二,以下代码运行时要满足三个文件夹下都有文件才能正常运行,而且默认的是清理三个文件夹,能力有限,无法写出指定清理那个文件夹的代码,代码如下:
程序测试图片:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("垃圾清理工具", 456, 304, 292, 215)
GUISetIcon("E:\系统类\mycom.ico", -1)
$Label1 = GUICtrlCreateLabel(" 清理当前用户临时文件夹", 104, 48, 139, 17)
$Label2 = GUICtrlCreateLabel("清理windows下临时文件夹", 104, 80, 141, 17)
$Label3 = GUICtrlCreateLabel("清理windows预读文件夹", 104, 120, 129, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 72, 48, 17, 17, -1, $WS_EX_CLIENTEDGE)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 72, 80, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox2", 72, 116, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Progress1 = GUICtrlCreateProgress(24, 232, 409, 17)
$Button2 = GUICtrlCreateButton("开始清理", 200, 160, 81, 25)
$Button1 = GUICtrlCreateButton("全选", 288, 160, 81, 25)
$Label4 = GUICtrlCreateLabel("运行状态:", 24, 200, 55, 17)
$Label5 = GUICtrlCreateLabel("", 88, 200, 232, 17)
$Group1 = GUICtrlCreateGroup("请选择操作项目", 48, 16, 337, 137, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
qx()
Case $Button2
dq()
EndSwitch
WEnd
Func qx()
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetState($Checkbox3,$GUI_CHECKED)
EndFunc
Func dq()
If $Checkbox1 Then
$m1=@UserProfileDir&"\"&"Local Settings\Temp"
;$ml="C:\123"
$lb1=_FileListToArray($m1)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb1=_ArrayMemeberInsert($lb1,$m1&"\");返回精数组1完整路径
EndIf
If $Checkbox2 Then
$m2="c:\windows\Temp"
;$ml="C:\123"
$lb2=_FileListToArray($m2)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb2=_ArrayMemeberInsert($lb2,$m2&"\");返回精数组1完整路径
EndIf
If $Checkbox3 Then
$m3="C:\WINDOWS\Prefetch"
;$ml="C:\123"
$lb3=_FileListToArray($m3)
;$size=DirGetSize($ml)
;_ArrayDisplay($lb,"$lb")
;MsgBox(0,"目录大小",$size/1000000&"M")
$lb3=_ArrayMemeberInsert($lb3,$m3&"\");返回精数组1完整路径
EndIf
;_ArrayDisplay($lb1,1)
;_ArrayDisplay($lb2,2)
;_ArrayDisplay($lb3,3)
;_ArrayDelete($lb1,0)
;_ArrayDelete($lb2,0)
;_ArrayDelete($lb3,0)
_ArrayConcatenate($lb1,$lb2)
_ArrayConcatenate($lb1,$lb3)
;_ArrayDisplay($lb1,"0");显示所有数据
$lb1=$lb1+$lb2+$lb3
;_ArrayDelete($lb1,0)
;MsgBox(0,0,$lb1)
;#cs
Dim $at
For $i=0 To $lb1
;MsgBox(0,"",($lb[$i]))
$at=FileGetAttrib($lb1[$i])
If $at="R" Or $at="H" Then
FileSetAttrib($lb1[$i],"-RH",1)
EndIf
If FileGetAttrib($lb1[$i])="D" Then
DirRemove($lb1[$i],1)
EndIf
FileDelete($lb1[$i])
GUICtrlSetData($Label5,"正在清理"&$lb1[$i])
GUICtrlSetData($Progress1,($i/$lb1)*100)
If GUICtrlRead($Progress1)=100 Then
GUICtrlSetData($Label5,"清理已完成,谢谢使用!")
EndIf
If $i<0 Then ExitLoop
Next
;#ce
EndFunc
;定义一个能让数组返回完整路径的函数_ArrayMemeberInsert
; 数组元素插入字符串 要插入的数组 插入的字符串 方向 0为左 1为右从第几个元素开始。
Func _ArrayMemeberInsert($__Array="",$__InsertString="",$__Direction=0,$__StartMember=1)
If $__Array="" Then Return
For $i=$__StartMember To UBound($__Array)-1 Step 1
Switch $__Direction
Case 0
$__Array[$i]=$__InsertString&$__Array[$i]
Case 1
$__Array[$i]=$__Array[$i]&$__InsertString
Case Else
ExitLoop
EndSwitch
Next
Return $__Array
EndFunc上面代码是前两天琢磨的,为了改进,我现在弄得以下这种形式,可是依然无法解决选择文件夹的功能,如果解决了选择文件夹的功能,但又不能解决进度条的问题,二者我只能解决一个问题,请各位指点一下,有兴趣的朋友来研究下,代码改进如下:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("垃圾清理工具", 456, 304, 292, 215)
GUISetIcon("E:\系统类\mycom.ico", -1)
Dim $Checkbox,$m,$lb
$Label1 = GUICtrlCreateLabel(" 清理当前用户临时文件夹", 104, 48, 139, 17)
$Label2 = GUICtrlCreateLabel("清理windows下临时文件夹", 104, 80, 141, 17)
$Label3 = GUICtrlCreateLabel("清理windows预读文件夹", 104, 120, 129, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox1", 72, 48, 17, 17, -1, $WS_EX_CLIENTEDGE)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 72, 80, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 72, 116, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_BOTTOM), $WS_EX_CLIENTEDGE)
$m=@UserProfileDir&"\"&"Local Settings\Temp"
$m="c:\windows\Temp"
$m="C:\WINDOWS\Prefetch"
$Progress1 = GUICtrlCreateProgress(24, 232, 409, 17)
$Button2 = GUICtrlCreateButton("开始清理", 200, 160, 81, 25)
$Button1 = GUICtrlCreateButton("全选", 288, 160, 81, 25)
$Label4 = GUICtrlCreateLabel("运行状态:", 24, 200, 55, 17)
$Label5 = GUICtrlCreateLabel("", 88, 200, 250, 20)
GUICtrlSetColor(-1, 0xff0000)
$Group1 = GUICtrlCreateGroup("请选择操作项目", 48, 16, 337, 137, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
qx()
Case $Button2
dq()
EndSwitch
WEnd
Func qx()
GUICtrlSetState($Checkbox,$GUI_CHECKED)
GUICtrlSetState($Checkbox,$GUI_CHECKED)
GUICtrlSetState($Checkbox,$GUI_CHECKED)
EndFunc
Func dq()
If GUICtrlRead($Checkbox)<>$GUI_CHECKED And GUICtrlRead($Checkbox)<>$GUI_CHECKED And GUICtrlRead($Checkbox)<>$GUI_CHECKED Then
GUISetState(@SW_DISABLE)
MsgBox(16,"提示","请选择要操作的项目",1)
GUISetState(@SW_ENABLE)
EndIf
Dim $ds=0
For $i=1 To 3
If GUICtrlRead($Checkbox[$i])=$GUI_CHECKED Then
$lb[$i]=_FileListToArray($i)
_ArrayDisplay($lb[$i],"0")
$lb[$i]=_ArrayMemeberInsert($lb[$i],$m[$i]&"\");返回精数组1完整路径
EndIf
Next
;_ArrayConcatenate($lb1,$lb)
;_ArrayConcatenate($lb1,$lb)
;_ArrayDisplay($lb1,"0");显示所有数据
;$lb1=$lb1+$lb2+$lb3
Dim $at
For $i=1 To $lb[$i-1]
;MsgBox(0,"",($lb[$i]))
$at=FileGetAttrib($lb[$i])
If $at="R" Or $at="H" Then
FileSetAttrib($lb[$i],"-RH",1)
EndIf
If FileGetAttrib($lb[$i])="D" Then
DirRemove($lb[$i],1)
EndIf
FileDelete($lb[$i])
GUICtrlSetData($Label5,"正在清理"&$lb[$i])
GUICtrlSetData($Progress1,($i/$lb)*100)
If GUICtrlRead($Progress1)=100 Then
GUICtrlSetData($Label5,"清理已完成,谢谢使用!")
EndIf
If $i<0 Then ExitLoop
Next
EndFunc
;定义一个能让数组返回完整路径的函数_ArrayMemeberInsert
; 数组元素插入字符串 要插入的数组 插入的字符串 方向 0为左 1为右从第几个元素开始。
Func _ArrayMemeberInsert($__Array="",$__InsertString="",$__Direction=0,$__StartMember=1)
If $__Array="" Then Return
For $i=$__StartMember To UBound($__Array)-1 Step 1
Switch $__Direction
Case 0
$__Array[$i]=$__InsertString&$__Array[$i]
Case 1
$__Array[$i]=$__Array[$i]&$__InsertString
Case Else
ExitLoop
EndSwitch
Next
Return $__Array
EndFunc
帮忙顶起..... 根据你的思路,修改代码如下:
进度算法有待完善,因为删除目录未算进百分比,建议递归,不过效率差点#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("垃圾清理工具", 456, 304, 292, 215)
GUISetIcon("E:\系统类\mycom.ico", -1)
Dim $Checkbox, $m, $lb
$Label1 = GUICtrlCreateLabel(" 清理当前用户临时文件夹", 104, 48, 139, 17)
$Label2 = GUICtrlCreateLabel("清理windows下临时文件夹", 104, 80, 141, 17)
$Label3 = GUICtrlCreateLabel("清理windows预读文件夹", 104, 120, 129, 17)
$Checkbox = GUICtrlCreateCheckbox("Checkbox1", 72, 48, 17, 17, -1, $WS_EX_CLIENTEDGE)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 72, 80, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_BOTTOM), $WS_EX_CLIENTEDGE)
$Checkbox = GUICtrlCreateCheckbox("Checkbox2", 72, 116, 17, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_BOTTOM), $WS_EX_CLIENTEDGE)
$m = @UserProfileDir & "\" & "Local Settings\Temp"
$m = "c:\windows\Temp"
$m = "C:\WINDOWS\Prefetch"
$Progress1 = GUICtrlCreateProgress(24, 232, 409, 17)
$Button2 = GUICtrlCreateButton("开始清理", 200, 160, 81, 25)
$Button1 = GUICtrlCreateButton("全选", 288, 160, 81, 25)
$Label4 = GUICtrlCreateLabel("运行状态:", 24, 200, 55, 17)
$Label5 = GUICtrlCreateLabel("", 88, 200, 250, 20)
GUICtrlSetColor(-1, 0xff0000)
$Group1 = GUICtrlCreateGroup("请选择操作项目", 48, 16, 337, 137, BitOR($GUI_SS_DEFAULT_GROUP, $BS_CENTER))
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
qx()
Case $Button2
dq()
EndSwitch
WEnd
Func qx()
GUICtrlSetState($Checkbox, $GUI_CHECKED)
GUICtrlSetState($Checkbox, $GUI_CHECKED)
GUICtrlSetState($Checkbox, $GUI_CHECKED)
EndFunc ;==>qx
Func dq()
Local $temp
If GUICtrlRead($Checkbox) <> $GUI_CHECKED And GUICtrlRead($Checkbox) <> $GUI_CHECKED And GUICtrlRead($Checkbox) <> $GUI_CHECKED Then
GUISetState(@SW_DISABLE)
MsgBox(16, "提示", "请选择要操作的项目", 1)
GUISetState(@SW_ENABLE)
EndIf
Dim $ds = 0
For $i = 1 To 3
If GUICtrlRead($Checkbox[$i]) = $GUI_CHECKED Then
$temp = _FileListToArray($m[$i]);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$temp = _ArrayMemeberInsert($temp, $m[$i] & "\");返回精数组1完整路径
_ArrayDelete($temp,0)
_ArrayConcatenate($lb,$temp)
$temp=0
EndIf
Next
_ArrayDelete($lb,0)
_ArrayDisplay($lb, "0")
;_ArrayConcatenate($lb1,$lb)
;_ArrayConcatenate($lb1,$lb)
;_ArrayDisplay($lb1,"0");显示所有数据
;$lb1=$lb1+$lb2+$lb3
Dim $at
For $i = 1 To UBound($lb)
;MsgBox(0,"",($lb[$i]))
$at = FileGetAttrib($lb[$i-1])
If $at = "R" Or $at = "H" Then
FileSetAttrib($lb[$i-1], "-RH", 1)
EndIf
If FileGetAttrib($lb[$i-1]) = "D" Then
DirRemove($lb[$i-1], 1)
ContinueLoop
EndIf
FileDelete($lb[$i-1])
GUICtrlSetData($Label5, "正在清理" & $lb[$i-1])
GUICtrlSetData($Progress1, ($i / UBound($lb) * 100))
Next
GUICtrlSetData($Label5, "清理已完成,谢谢使用!")
EndFunc ;==>dq
;定义一个能让数组返回完整路径的函数_ArrayMemeberInsert
; 数组元素插入字符串 要插入的数组 插入的字符串 方向 0为左 1为右从第几个元素开始。
Func _ArrayMemeberInsert($__Array = "", $__InsertString = "", $__Direction = 0, $__StartMember = 1)
If $__Array = "" Then Return
For $i = $__StartMember To UBound($__Array) - 1 Step 1
Switch $__Direction
Case 0
$__Array[$i] = $__InsertString & $__Array[$i]
Case 1
$__Array[$i] = $__Array[$i] & $__InsertString
Case Else
ExitLoop
EndSwitch
Next
Return $__Array
EndFunc ;==>_ArrayMemeberInsert
thank you 下班后回去再研究一下,呵呵 没搞明白$ds变量干什么用 还有就是感觉楼主思路有点繁琐 $ds变量想用来统计所选文件总量的,还没弄好,有兴趣的兄弟帮忙看一下哈 收藏。谢谢分享 代码收藏了,谢谢...... 如果调用DOS命令DIR显示对应文件夹的信息到某.TXT文本,在处理进度条和清除文件之前,读取并判断容量,如何?个人认为,如果显示总容量为0,根据不用调用删除和进度条显示,如果总容量大于0,说明有需要清理的内容,直接读取对应内容,删除的同时可以显示清除内容。
可以先测试下DIR /? |MORE >A.TXT 学习了,三楼代码不错! 研究了一下P版的代码,确实进度条不是很准确,有时候清除完后,再次点清除进度条会显示不完整,而且本人的代码中93-94行为先清除文件的隐藏和只读属性,然后再删除文件和文件夹,但清除属性的代码好像没有起到作用,另外AU3不用强制删除文件,有些文件无法强制性删除,如果再做到这点就基本上完美一点了。9楼的思路不错,但还是要用批处理来做,本人还是想用纯AU3代码完成。谢谢各位兄弟,有兴趣继续一起完善吧。 对了,$ds变量好像现在代码中没有作用,可以删除掉 根据你的思路,修改代码如下:
进度算法有待完善,因为删除目录未算进百分比,建议递归,不过效率差点
pcbar 发表于 2011-5-12 16:48 http://www.autoitx.com/images/common/back.gif
好像不是很完美的。有时间研究一下了。 路过不放过 路过不放过
页:
[1]
2