Jump to content
Sign in to follow this  
cramaboule

Delete Temp Files

Recommended Posts

cramaboule

Here is a script to delete *.tmp files and and temporary folder.

An easy one !

#Include <File.au3>
#Include <Array.au3>

$Debug=0

Func EmptyFolder($FolderToDelete)
    $AllFiles=_FileListToArray($FolderToDelete,"*",0)
    If $Debug Then MsgBox(0,"",$FolderToDelete)
    If IsArray($AllFiles) Then
        If $Debug Then 
            _ArrayDisplay( $AllFiles,$FolderToDelete)
        EndIf
        For $i = 1 To $AllFiles[0]
            FileDelete($FolderToDelete & "\" & $AllFiles[$i])
            DirRemove($FolderToDelete & "\" & $AllFiles[$i], 1)    
        Next
    EndIf
EndFunc

EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files\Content.IE5")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files")
EmptyFolder (@HomeDrive & @HomePath & "\Cookies")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\History")
EmptyFolder (@HomeDrive & "\Temp\Temporary Internet Files")
EmptyFolder (@WindowsDir & "\Temp")
EmptyFolder (@HomeDrive & @HomePath & "\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Application Data\Microsoft\Office\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temp")

Cram...

Share this post


Link to post
Share on other sites
cramaboule

#Include <File.au3>
#Include <Array.au3>

$Debug=0

Func EmptyFolder($FolderToDelete)
    $AllFiles=_FileListToArray($FolderToDelete,"*",0)
    If $Debug Then ConsoleWrite("-->" & $FolderToDelete & @CRLF )
    If IsArray($AllFiles) Then
        If $Debug Then 
            _ArrayDisplay( $AllFiles,$FolderToDelete)
        EndIf
        For $i = 1 To $AllFiles[0]
            $delete = FileDelete($FolderToDelete & "\" & $AllFiles[$i])
            If $Debug Then
                ConsoleWrite($FolderToDelete & "\" & $AllFiles[$i]& " =>"&$delete & @CRLF  )
            EndIf
            DirRemove($FolderToDelete & "\" & $AllFiles[$i], 1)    
        Next
    EndIf
EndFunc

EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files\Content.IE5")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files")
EmptyFolder (@HomeDrive & @HomePath & "\Cookies")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\History")
EmptyFolder (@HomeDrive & "\Temp\Temporary Internet Files")
EmptyFolder (@WindowsDir & "\Temp")
EmptyFolder (@HomeDrive & "\Temp")
EmptyFolder (@HomeDrive & @HomePath & "\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Application Data\Microsoft\Office\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temp")

ShellExecuteWait("RunDll32.exe"," InetCpl.cpl,ClearMyTracksByProcess 255")

Added the ShellExecuteWait then NOW the Temporary Internet Files are really deleted !

Cram...

Share this post


Link to post
Share on other sites
Hellooopsforgotsendcommand

would it not be better to have temp files deleted from the windows dir only if they are older than a day. i.e. not that days files?

Share this post


Link to post
Share on other sites
insignia96

#Include <File.au3>
#Include <Array.au3>

$Debug=1

Func EmptyFolder($FolderToDelete)
    $AllFiles=_FileListToArray($FolderToDelete,"*",0)
    If $Debug Then ConsoleWrite("-->" & $FolderToDelete & @CRLF )
    If IsArray($AllFiles) Then
        If $Debug Then
            _ArrayDisplay( $AllFiles,$FolderToDelete)
        EndIf
        For $i = 1 To $AllFiles[0]
            $crt = FileGetTime( $FolderToDelete & "\" & $AllFiles[$i], 1 )
            If $crt[2] = @MDAY And $crt[0] = @YEAR And $crt[1] = @MON Then
                If $Debug Then
                    ConsoleWrite( $FolderToDelete & "\" & $AllFiles[$i] & " --> Today's File, Skipping!" & @CRLF )
                EndIf
                ContinueLoop
            EndIF
            $delete = FileDelete($FolderToDelete & "\" & $AllFiles[$i])
            If $Debug Then
                ConsoleWrite($FolderToDelete & "\" & $AllFiles[$i]& " =>"&$delete & @CRLF  )
            EndIf
            DirRemove($FolderToDelete & "\" & $AllFiles[$i], 1)
        Next
    EndIf
EndFunc

EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files\Content.IE5")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temporary Internet Files")
EmptyFolder (@HomeDrive & @HomePath & "\Cookies")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\History")
EmptyFolder (@HomeDrive & "\Temp\Temporary Internet Files")
EmptyFolder (@WindowsDir & "\Temp")
EmptyFolder (@HomeDrive & "\Temp")
EmptyFolder (@HomeDrive & @HomePath & "\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Application Data\Microsoft\Office\Recent")
EmptyFolder (@HomeDrive & @HomePath & "\Local Settings\Temp")

ShellExecuteWait("RunDll32.exe"," InetCpl.cpl,ClearMyTracksByProcess 255")

That Should do it. I think :)

Edited by insignia96

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Share this post


Link to post
Share on other sites
murray654

That Should do it. I think :D

Hi,

Great script - I modified it to delete files older than 1 hour - do you foresee any problem with doing this?

Another question; this script does not delete read only files - is this by design?

Cheers,

Murray

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  

×