Archive: RmDir error because Command line shell


RmDir error because Command line shell
Hi,

I try to remove a folder and all its contents (RMDir /r). But when i have a open Command Shell which shows the content of the folder which i want to remove i get an error. All files and subfolders will be removed but the folder itself is still there. I made already sure that the SetOutPath points to another folder. I guess the open shell locks the folder which i want to delete and prevent to remove it.
Is there a workaround or a way to figure out if a folder is lockend by a process and close that process which is locking it?


Thank you for your help.


M.


This seems to work fine:


CreateDirectory "D:\Program Files\NSIS\Projects\Testing\ja"
Exec 'explorer "D:\Program Files\NSIS\Projects\Testing\ja"'
Sleep 5000
RMDir /r "D:\Program Files\NSIS\Projects\Testing\ja"


Explorer window opens showing folder "ja" then closes after 5 seconds when the folder is deleted.

-Stu

Hi Stu,

thank you for your quick answer.

I tried out what you suggested but it doesnt work.

Sleep 5000
RMDir /r "$INSTDIR"

It removes the folder sucessfully when i dont have a shell window showing the content of that folder. But not otherwise, even with the 5 sec delay.

M.


What Windows are you running?
By shell window do you mean Windows Explorer (explorer.exe)?
What code are you using to view the folder contents?

Try my example in a single Section but use $INSTDIR instead:


Section "blah"
CreateDirectory "$INSTDIR"
Exec 'explorer "$INSTDIR"'
Sleep 5000
RMDir /r "$INSTDIR"
SectionEnd


-Stu

The shell what i am talking about is the command line shell (cmd.exe). I dont have a problem with the Windows Explorer.

The described behavior only happens with such a command shell.

I hopes that helps to understand my problem.

M.


Hmm I see now, missed the Command Shell from your first post :(

Well will Command Prompt always be open? In which way is it viewing the folder... with the dir command or some other executable?

I don't know of a way to find out which process last accessed the folder, but that would be your best solution. Otherwise, you could probably close Command Prompt with FindWindow and SendMessage with ${WM_CLOSE}.

-Stu


First of all might be good to understand why console stays open. NSIS distribution includes nsExec plug-in for DOS applications, ExecDos and ExecCmd are available in archive, plug-ins can solve the problem for most of apps (not 100%, test required). From the other side, if user opened console, might be better to leave it as it is (and do not rmdir).
Win9x consoles not accepted windows messages in my tests.