Bernd Braun Posted August 22, 2006 Posted August 22, 2006 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
buzz44 Posted August 22, 2006 Posted August 22, 2006 (edited) 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 August 23, 2006 by Larry qq
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now