Jump to content
Sign in to follow this  
Bernd Braun

Clean Temp Directories on PCs silent

Recommended Posts

Bernd Braun

Here is the script - but the error handling is not working - if a file is in use:

#include <file.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

If FileExists (@WindowsDir & "\temp\*.*") Then

$error = DeleteFolderContent(@WindowsDir & "\temp\*.*")

writelogFilecopy(@WindowsDir & "\temp\*.*" ,$error)

EndIf

If FileExists (@HomeDrive & "\TND\Agents\Log\*.*") Then

$error = DeleteFolderContent (@HomeDrive & "\TND\Agents\Log\*.*")

writelogFilecopy(@HomeDrive & "\TND\Agents\Log\*.*",$error)

EndIf

If FileExists (@TempDir & "\*.*") Then

$error = DeleteFolderContent(@TempDir & "\*.*")

writelogFilecopy(@TempDir & "\*.*",$error)

EndIf

$localsettingtemp = @UserProfileDir & "\Lokale Einstellungen\temp\*.*"

If FileExists ($localsettingtemp) Then

$error = DeleteFolderContent ($localsettingtemp)

writelogFilecopy($localsettingtemp,$error)

EndIf

Func DeleteFolderContent($FolderSpec)

Local $fso

$fso = ObjCreate("Scripting.FileSystemObject")

;Delete all files in folder

$fso.DeleteFile($FolderSpec)

Here comes the error if a file is in use (e.g. Word Document)

;Delete all folders

$fso.DeleteFolder($FolderSpec)

EndFunc

Func writelogFilecopy($info,$value)

DirCreate("c:\gb\deletetemp")

if $value = "1" Then

_FileWriteLog("c:\gb\deletetemp" & @ComputerName & ".log" ,$info & " ---- OK ")

EndIf

If $value = "0" Then

_FileWriteLog("c:\gb\deletetemp" & @ComputerName & ".log",$info & " ---- Dircopy Failed ")

EndIf

EndFunc

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8) ; for displaying purposes

Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $oMyError.description & @CRLF & _

"err.number is: " & @TAB & $HexNumber & @CRLF & _

"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF _

)

SetError(1) ; to check for after this function returns

Return

Endfunc

Share this post


Link to post
Share on other sites
buzz44

If you can, kill explorer at the start of the script, and run it again using...

Run ("explorer.exe")
;and
ProcessClose ("explorer.exe")

Or only do that IF a file is in use.

Edited by Larry

qq

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.