Jump to content

filedelete failure reasons


jaja714
 Share

Recommended Posts

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

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 by Musashi

Musashi-C64.png

"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

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 by jaja714
Link to comment
Share on other sites

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 by Musashi

Musashi-C64.png

"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

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

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 ;)) :

#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)

 

Musashi-C64.png

"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

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 by jaja714
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...