Jump to content

Return Value of DriRemove?


Archer
 Share

Recommended Posts

Hi, all

That's a little weird. If I use the following code to test the DirRemove() function, the failure would be shown in the log.

However, I did not open this folder or something and I do have the admin permission. Why?

One more thing to mention is that although the error code is 0 but the folder is gone..... Why this? If it could be delete the folder totally, it should be successful with returning code 1.

-------------------

#include <File.au3>

$csLogFileFullPath = "test.log"

$sFileName = "C:\Test1"

DirCreate($sFileName)

If FileExists($sFileName) Then

_FileWriteLog($csLogFileFullPath, $sFileName & " exists.")

EndIf

DirRemove($sFileName, 0)

If @error = 0 Then

_FileWriteLog($csLogFileFullPath, "Failed to delete folder " & $sFileName)

Else

_FileWriteLog($csLogFileFullPath, "Delete folder " & $sFileName & " successfully!")

EndIf

-------------------

DirRemove() Return Value

Success: Returns 1.

Failure: Returns 0 if there is an error removing the directory (or if directory does not exist).

Edited by Archer
Link to comment
Share on other sites

You are aware that DirCreate() can fail as well, right? It doesn't hurt to make sure the folder is created properly before deleting. You check if it exists and write to the log if it does but you try to remove it even if the folder doesn't.

Link to comment
Share on other sites

Hi!

If NOT DirRemove($sFileName, 0) Then
_FileWriteLog($csLogFileFullPath, "Failed to delete folder " & $sFileName)

Would work. The @error should be 0 if success. The returnvalue on the other hand should be 1. :)

/Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

...or...

If @error Then
_FileWriteLog($csLogFileFullPath, "Failed to delete folder " & $sFileName)

Would work. The @error should be 0 if success. The returnvalue on the other hand should be 1. :)

/Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

You are aware that DirCreate() can fail as well, right? It doesn't hurt to make sure the folder is created properly before deleting. You check if it exists and write to the log if it does but you try to remove it even if the folder doesn't.

No. I just wonder to know that the DirRemove() has been successfully removed the folder, why return error code 0?

If you run the script you got know that the folder exists but in the next steps, the log show "fail to delete....", just here, why?

Link to comment
Share on other sites

...or...

If @error Then
_FileWriteLog($csLogFileFullPath, "Failed to delete folder " & $sFileName)

Would work. The @error should be 0 if success. The returnvalue on the other hand should be 1. :)

/Manko

Thanks. It works.

I wonder to know that why @error = 0 does not work as I expected?

Link to comment
Share on other sites

Thanks. It works.

I wonder to know that why @error = 0 does not work as I expected?

Because if @error is 0 it is not an error. :)

/Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
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...