Sign in to follow this  
Followers 0
Archer

Return Value of DriRemove?

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Does the folder exist?

Of course the folder exists. You could refer the script above and the folder was created before DirRemove.

Share this post


Link to post
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.

Share this post


Link to post
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...

Share this post


Link to post
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...

Share this post


Link to post
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?

Share this post


Link to post
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?

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

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

/Manko

Ohhhhhh, Thanks. :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0