Old 24th March 2006, 20:10   #1
M-Force
Junior Member
 
Join Date: Mar 2006
Posts: 28
Question 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.
M-Force is offline   Reply With Quote
Old 24th March 2006, 20:51   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
This seems to work fine:
code:

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
Afrow UK is offline   Reply With Quote
Old 24th March 2006, 21:08   #3
M-Force
Junior Member
 
Join Date: Mar 2006
Posts: 28
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.
M-Force is offline   Reply With Quote
Old 24th March 2006, 22:49   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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:
code:

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



-Stu
Afrow UK is offline   Reply With Quote
Old 27th March 2006, 15:01   #5
M-Force
Junior Member
 
Join Date: Mar 2006
Posts: 28
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.
M-Force is offline   Reply With Quote
Old 27th March 2006, 15:05   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 27th March 2006, 15:26   #7
Takhir
Major Dude
 
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
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.
Takhir is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump