Sign in to follow this  
Followers 0
SoulBlade

DiskCleaner v1.0

7 posts in this topic

I'm writing a tool to delete temporary files from disk, without using system variables like %userprofile% or %windir%.

This program was created to run in BartPE but runs in "normal" Windows.

This program is far from finished, and has the following problems:

- If files are hidden or with system properties, they aren't deleted;

- Code for cleaned files size isn't done.

- Run button is disabled only a couple of seconds of being pressed (should be right after clicking).

Please feel free to improve this code, in any way you seem fit, including solving the above problems.

I'm just begining in Autoit v3 world!

:">

CODE
AutoItSetOption("TrayIconHide", 1)

#include <GUIConstants.au3>

#include <Array.au3>

$s=0

$dsk = DriveGetDrive( "fixed" )

For $i = 1 to $dsk[0]

$s=$s+90

next

$s=$s+80

GUICreate("DiskCleaner 1.0", 345, $s)

GUISetIcon("diskcleaner.ico", 0)

$run= GUICtrlCreateButton("RUN", 135, $s-50, 80, 30)

$nan= GUICtrlCreateLabel("© Autoit3", 270, $s-15, 60, 12)

GUICtrlSetFont($nan,7)

$y= 30

$z= 50

If NOT @error Then

For $i = 1 to $dsk[0]

GUICtrlCreateGroup ("Disk "& StringUpper($dsk[$i]) & " before", 10, $y, 155, 70)

GUICtrlCreateGroup ("Disk "& StringUpper($dsk[$i]) & " after", 180, $y, 155, 70)

$y=$y+90

GUICtrlCreateLabel("Total Space: ",15, $z, 70,15,$SS_RIGHT)

$g1=GUICtrlCreateLabel(Round(DriveSpacetotal($dsk[$i]),0) &" MB", 90, $z, 60, 15,BitOR($BS_PUSHLIKE,$SS_RIGHT))

GUICtrlSetColor($g1, 0x0066f6)

GUICtrlCreateLabel("Cleaned: ",185, $z, 70,15,$SS_RIGHT)

$Label=GUICtrlCreateLabel(0 &" MB", 260, $z, 60, 15,BitOR($BS_PUSHLIKE,$SS_RIGHT))

$z=$z+20

GUICtrlCreateLabel("Free Space: ",15, $z, 70,15,$SS_RIGHT)

$g2=GUICtrlCreateLabel(Round(DriveSpaceFree($dsk[$i]),0) &" MB", 90, $z, 60, 15,BitOR($BS_PUSHLIKE,$SS_RIGHT))

GUICtrlSetColor($g2, 0x0066f6)

GUICtrlCreateLabel("Free Space: ",185, $z, 70,15,$SS_RIGHT)

$g3=GUICtrlCreateLabel(Round(DriveSpacefree($dsk[$i]),0) &" MB", 260, $z, 60, 15,BitOR($BS_PUSHLIKE,$SS_RIGHT))

GUICtrlSetColor($g3, 0x0066f6)

$z=$z+70

Next

EndIf

GUISetState()

Do

$msg = GUIGetMsg()

Select

Case $msg= $Run

$z=70

GUICtrlSetState ($run, $GUI_DISABLE)

$fil1 = _FileSearch('*.aaa')

For $ir = 1 to $fil1[0]

FileSetAttrib ( $fil1[$ir], "-R")

FileDelete($fil1[$ir])

next

$fil2 = _FileSearch('*.bbb')

For $ir = 1 to $fil2[0]

FileSetAttrib ( $fil2[$ir], "-R")

FileDelete($fil2[$ir])

next

$fil3 = _FileSearch('*.ccc')

For $ir = 1 to $fil3[0]

FileSetAttrib ( $fil3[$ir], "-R")

FileDelete($fil3[$ir])

next

$fil4 = _FileSearch('*.ddd')

For $ir = 1 to $fil4[0]

FileSetAttrib ( $fil4[$ir], "-R")

FileDelete($fil4[$ir])

next

$fil5 = _FileSearch('*.eee')

For $ir = 1 to $fil5[0]

FileSetAttrib ( $fil5[$ir], "-R")

FileDelete($fil5[$ir])

next

if $msg= $GUI_EVENT_CLOSE then exit

Case $msg= $GUI_EVENT_CLOSE

exit

EndSelect

Until $msg = $GUI_EVENT_CLOSE

Func _FileSearch($s_Mask = '', $i_Recurse = 1)

Local $s_Command = ' /c dir /B "'

If $i_Recurse = 1 Then $s_Command = ' /c dir /B /S "'

$dc = DriveGetDrive( "fixed" )

$s_Buf = ''

For $i = 1 to $dc[0] Step 1

$i_Pid = Run(@ComSpec & $s_Command & $dc[$i] & "\" & $s_Mask, "", @SW_HIDE, 2+4)

$g3=GUICtrlCreateLabel(Round(DriveSpacefree($dsk[$i]),0) &" MB", 260, $z, 60, 15,BitOR($BS_PUSHLIKE,$SS_RIGHT))

GUICtrlSetColor($g3, 0xFF0000)

$z=$z+90

if $z>$s-50 then $z=70

While 1

$s_BufX = StdoutRead($i_Pid)

If @error Then ExitLoop

$s_Buf &= $s_BufX

WEnd

next

$s_Buf = StringSplit(StringTrimRight($s_Buf, 2), @CRLF, 1)

If UBound($s_Buf) = 2 AND $s_Buf[1] = '' Then SetError(1)

Return $s_Buf

EndFunc;==>_FileSearch

Share this post


Link to post
Share on other sites



I second Volly. CCleaner is great.

Share this post


Link to post
Share on other sites

- If files are hidden or with system properties, they aren't deleted

Try this:

Func _FileSearch($s_Mask = '', $i_Recurse = 1, $l_Option)

; $l_Option must be a combination of D,R,A,S, and/or H

If $l_Option Not "" Then
$l_Option = "-" & $l_Option

$l_Attrib = "/A" & $l_Option

$i_Pid = Run(@ComSpec & $s_Command & $l_Attrib & $dc[$i] & "\" & $s_Mask, "", @SW_HIDE, 2+4)

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Volly and Weaponx, you're missing the point.

Like i said, i'm writing a custom tool to delete files and folders using BartPe, not in normal Windows.

Programs like CCleaner or Cleanup (i personaly use Cleanup and know very well CCleaner) are useless in BartPe because they use Windows Variables.

Besides, i want to delete somes files and folders that CCleaner and others don't remove anyway.

Asley thanks for that link.

For what i saw, DiskMax also relies in windows variables, but i belive i can learn from this code.

Thanks!

Edited by SoulBlade

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0