Search the Community
Showing results for tags 'FileDelete x64'.
-
Hello, The following script is meant to delete all files in C:\Users\<username>\AppData\Local\Temp. There are a couple of exceptions and that logic works OK. Unfortunately the FileDelete always returns Status <> 1 (delete failed) and I don't understand why. The OS where the script is running is W7 x64. I mention this because I wonder whether there is something funny going on due to the OS. In the While loop I needed to add a check for a blank file name on the 2nd line of the loop because otherwise the FileFindFirstFile returns a never-ending list of blank entries after all of the real file & directory entries are returned (and I have not seen that behaviour before). As for why the FileDelete does not work, I'm guessing I've done something silly which I keep missing. It is not a NTFS permissions issue nor is it a RunAs issue. ; Obtain list of user directories $search = FileFindFirstFile("C:\Users\*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If $file = "" Then ExitLoop ConsoleWrite("Directory: " & $file & @CRLF) If @error Then ExitLoop If $file = "Default" Then ConsoleWrite("Directory: " & $file & " skipped" & @CRLF) ContinueLoop EndIf If $file = "Default User" Then ConsoleWrite("Directory: " & $file & " skipped" & @CRLF) ContinueLoop EndIf If $file = "All Users" Then ConsoleWrite("Directory: " & $file & " skipped" & @CRLF) ContinueLoop EndIf If $file = "Public" Then ConsoleWrite("Directory: " & $file & " skipped" & @CRLF) ContinueLoop EndIf If Not StringInStr(FileGetAttrib("C:\Users\" & $file),"D") Then ConsoleWrite("File: " & $file & " skipped" & @CRLF) ContinueLoop EndIf ; Process directory If FileExists("C:\Users\" & $file & "\AppData\Local\Temp") Then $Status = FileDelete("C:\Users\" & $file & "\AppData\Local\Temp\*.*") ConsoleWrite("C:\Users\" & $file & "\AppData\Local\Temp\*.*" & @CRLF) If $Status = 1 Then ConsoleWrite("Clean Temp successful : " & $file & @CRLF) Else ConsoleWrite("*** Clean Temp failed *** : " & $file & @CRLF) EndIf Else ConsoleWrite("C:\Users\" & $file & "\AppData\Local\Temp : not found" & @CRLF) EndIf WEnd ; Close the search handle FileClose($search) Appreciate suggestions on how to troubleshoot, or where I have stuffed up. Thanks VW