jaja714 Posted September 15, 2020 Share Posted September 15, 2020 When running the following code from SciTE in admin mode: cleanIt('C:\windows\Temp\mat-debug-5288.log') cleanIt('C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log') Func cleanIt($file) FileDelete($file) If @error = 0 Then ConsoleWrite(@extended &@TAB& FileGetAttrib($file) &@TAB& $file &@CRLF) EndFunc ;==>cleanIt I get the following FileDelete failures: >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "...\AutoIt\test.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop 32 N C:\windows\Temp\mat-debug-5288.log 32 N C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log +>13:03:33 AutoIt3.exe ended.rc:0 +>13:03:33 AutoIt3Wrapper Finished. Why? NOTE: I can delete the files manually from Windows Explorer without any admin rights. Link to comment Share on other sites More sharing options...
Musashi Posted September 15, 2020 Share Posted September 15, 2020 (edited) cleanIt('C:\windows\Temp\mat-debug-5288.log') cleanIt('C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log') Func cleanIt($file) ConsoleWrite($file & @CRLF) ConsoleWrite(FileGetAttrib($file) & @CRLF) If Not FileDelete($file) Then ConsoleWrite("! >>> File not deleted" & @CRLF) EndIf EndFunc ;==>cleanIt EDIT : You are mixing up the return value of the function (1=Success, 0=Failure) with the error macro. The error macro(@error) is always 0 (here). Edited September 15, 2020 by Musashi Danp2 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jaja714 Posted September 18, 2020 Author Share Posted September 18, 2020 (edited) True but, then again, the if...then only applies to the ConsoleWrite statement and does not affect the FileDelete operation IN ANY WAY. So, the question remains ... Why aren't these files getting deleted? Edited September 18, 2020 by jaja714 Link to comment Share on other sites More sharing options...
KaFu Posted September 18, 2020 Share Posted September 18, 2020 Windows dir sounds like a protected / elevated path, re-test with #RequireAdmin added to the top of the script. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Musashi Posted September 18, 2020 Share Posted September 18, 2020 (edited) 28 minutes ago, jaja714 said: Musashi, please check the documentation on FileDelete. It clearly says @error is 0 when the file cannot be deleted. NO, the documentation on FileDelete clearly states : Return Value : Success : 1 Failure : 0 if files are not deleted or do not exist. @jaja714 : Edit I have successfully tested the following code on my PC (Win 7). cleanIt('C:\windows\Temp\mat-debug-5288.log') cleanIt('C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log') Func cleanIt($file) ConsoleWrite($file & @CRLF) ConsoleWrite(FileGetAttrib($file) & @CRLF) If Not FileDelete($file) Then ConsoleWrite("! >>> File not deleted" & @CRLF) Else ConsoleWrite("+ >>> File deleted" & @CRLF) EndIf EndFunc ;==>cleanIt The @error macro is not even mentioned, at least in my version of the help. But try it anyway with #RequireAdmin, like @KaFu suggested. Edited September 18, 2020 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jaja714 Posted September 18, 2020 Author Share Posted September 18, 2020 3 hours ago, KaFu said: Windows dir sounds like a protected / elevated path, re-test with #RequireAdmin added to the top of the script. Kafu, as per my original post, I tried RequireAdmin and ran scite as admin ... to no avail. Most of the files in Windows Temp are deleteable ... just not these ones. Also, as per my original post, I can delete them manually, without admin. Musahi, you are right, I realized my error and edited as soon as I posted but you were too fast!!! The bottom line is that the files still cannot be deleted. Link to comment Share on other sites More sharing options...
Dan_555 Posted September 18, 2020 Share Posted September 18, 2020 (edited) Edit: My question was answered in the 1st post ... Edited September 18, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Musashi Posted September 18, 2020 Share Posted September 18, 2020 16 minutes ago, jaja714 said: Most of the files in Windows Temp are deleteable ... just not these ones. Also, as per my original post, I can delete them manually, without admin. 14 minutes ago, jaja714 said: Musashi, you are right, I realized my error and edited as soon as I posted but you were too fast!!! The bottom line is that the files still cannot be deleted. Just a test (quick & dirty ) : expandcollapse popup#include <WinAPIFiles.au3> Local $sFile1, $sFile2 $sFile1 = 'C:\windows\Temp\mat-debug-5288.log' $sFile2 = 'C:\windows\Temp\officeclicktorun.exe_streamserver(2020080309013714A8).log' ConsoleWrite(" --------------------------------------------" & @CRLF) ConsoleWrite("> File = " & $sFile1 & @CRLF) If FileExists($sFile1) Then ConsoleWrite("+ >>> File found" & @CRLF) ConsoleWrite(" >>> File in use = " & _WinAPI_FileInUse($sFile1) & @CRLF) ConsoleWrite(" >>> Attributs before = " & FileGetAttrib($sFile1) & @CRLF) If Not FileSetAttrib($sFile1, "-R+A-S-H-N") Then ConsoleWrite("! Problem setting attributes." & @CRLF) EndIf ConsoleWrite(" >>> Attributs after = " & FileGetAttrib($sFile1) & @CRLF) Else ConsoleWrite("! >>> File not found" & @CRLF) EndIf ConsoleWrite(" --------------------------------------------" & @CRLF) ConsoleWrite("> File = " & $sFile2 & @CRLF) If FileExists($sFile2) Then ConsoleWrite("+ >>> File found" & @CRLF) ConsoleWrite(" >>> File in use = " & _WinAPI_FileInUse($sFile2) & @CRLF) ConsoleWrite(" >>> Attributs before = " & FileGetAttrib($sFile2) & @CRLF) If Not FileSetAttrib($sFile2, "-R+A-S-H-N") Then ConsoleWrite("! Problem setting attributes." & @CRLF) EndIf ConsoleWrite(" >>> Attributs after = " & FileGetAttrib($sFile2) & @CRLF) Else ConsoleWrite("! >>> File not found" & @CRLF) EndIf ConsoleWrite(" --------------------------------------------" & @CRLF) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jaja714 Posted September 18, 2020 Author Share Posted September 18, 2020 (edited) My pc was rebooted (security update) and the files are gone so I can't recreate this anymore. Perhaps those files were locked and I couldn't delete them but that doesn't explain why I was able to delete them (and restore them from the recycle bin) over and over. The bottom line is that I was hoping fileDelete was using @extended to return more information when a file can't be deleted. Musashi, I like the fileinuse logic and I will incorporate that into my temp files cleanup routine. Edited September 18, 2020 by jaja714 Musashi 1 Link to comment Share on other sites More sharing options...
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