Board index » cppbuilder » Problems to remove a folder

Problems to remove a folder


2004-02-23 06:20:49 PM
cppbuilder85
Hello,
If I try to remove an empty folder using RemoveDir I get the error msg 'Access denied' (0x00000005). I examined the problem and found out that If I previously select some files in it using TOpenDialog the folder remains occupied by my app. I tried to create OpenDialog during runtime only using new and delete but no success. What can I do?
 
 

Re:Problems to remove a folder

Roland wrote:
Quote
If I try to remove an empty folder using RemoveDir I get the error msg 'Access denied' (0x00000005). I examined the problem and found out that If I previously select some files in it using TOpenDialog the folder remains occupied by my app. I tried to create OpenDialog during runtime only using new and delete but no success. What can I do?
Please wrap lines.
Think that your working directory or current directory stays
that directory then.
First change the workingdirectory to a directory different
from the one you want to delete.
Hans.
 

Re:Problems to remove a folder

I 've done it - no success. I copied all my files I want to
proceed to a temp folder so the I must not work in this
folder the app still remains it occupied.
Roland.
Hans Galema < XXXX@XXXXX.COM >wrote:
Quote
Roland wrote:

>If I try to remove an empty folder using RemoveDir I get the error msg 'Access denied' (0x00000005). I examined the problem and found out that If I previously select some files in it using TOpenDialog the folder remains occupied by my app. I tried to create OpenDialog during runtime only using new and delete but no success. What can I do?

Please wrap lines.

Think that your working directory or current directory stays
that directory then.

First change the workingdirectory to a directory different
from the one you want to delete.

Hans.
 

{smallsort}

Re:Problems to remove a folder

Roland,
When the open dialog selects a file, the directory that the file is in
becomes the 'current directory' for that application. If your application
tries to delete that directory, it can't as it is still 'current'. After
using the open dialog, change the current directory using the WinAPI to some
other directory and you should be OK.
HTH Pete
"Roland" < XXXX@XXXXX.COM >wrote in message
Quote

I 've done it - no success. I copied all my files I want to
proceed to a temp folder so the I must not work in this
folder the app still remains it occupied.

Roland.

Hans Galema < XXXX@XXXXX.COM >wrote:
>Roland wrote:
>
>>If I try to remove an empty folder using RemoveDir I get the error msg
'Access denied' (0x00000005). I examined the problem and found out that If I
previously select some files in it using TOpenDialog the folder remains
occupied by my app. I tried to create OpenDialog during runtime only using
new and delete but no success. What can I do?
Quote
>
>Please wrap lines.
>
>Think that your working directory or current directory stays
>that directory then.
>
>First change the workingdirectory to a directory different
>from the one you want to delete.
>
>Hans.

 

Re:Problems to remove a folder

Hello Pete,
...it's unbelievable persistent. I altered the current dir using 'SetCurrentDirectory()' and checked it afterwards with 'GetCurrentdirectory()' but RemoveDir fails.
I build a workaround using a batch file that starts an exe which is then erasing the folder. That works. If I run the exe from my app it don't work. I have to terminate my app before I can do it. It's very mysterious!
Roland
"Pete Fraser" < XXXX@XXXXX.COM >wrote:
Quote
Roland,
When the open dialog selects a file, the directory that the file is in
becomes the 'current directory' for that application. If your application
tries to delete that directory, it can't as it is still 'current'. After
using the open dialog, change the current directory using the WinAPI to some
other directory and you should be OK.
HTH Pete

"Roland" < XXXX@XXXXX.COM >wrote in message
news:4039e806$ XXXX@XXXXX.COM ...
>
>I 've done it - no success. I copied all my files I want to
>proceed to a temp folder so the I must not work in this
>folder the app still remains it occupied.
>
>Roland.
>
>Hans Galema < XXXX@XXXXX.COM >wrote:
>>Roland wrote:
>>
>>>If I try to remove an empty folder using RemoveDir I get the error msg
'Access denied' (0x00000005). I examined the problem and found out that If I
previously select some files in it using TOpenDialog the folder remains
occupied by my app. I tried to create OpenDialog during runtime only using
new and delete but no success. What can I do?
>>
>>Please wrap lines.
>>
>>Think that your working directory or current directory stays
>>that directory then.
>>
>>First change the workingdirectory to a directory different
>>from the one you want to delete.
>>
>>Hans.
>


 

Re:Problems to remove a folder

Something in your app must be using that directory.
Perhaps you can step through it and try to delete the directory from File
Explorer. What's in the directory?
Rgds Pete
"Roland" < XXXX@XXXXX.COM >wrote in message
Quote

Hello Pete,

...it's unbelievable persistent. I altered the current dir using
'SetCurrentDirectory()' and checked it afterwards with
'GetCurrentdirectory()' but RemoveDir fails.
Quote

I build a workaround using a batch file that starts an exe which is then
erasing the folder. That works. If I run the exe from my app it don't work.
I have to terminate my app before I can do it. It's very mysterious!
 

Re:Problems to remove a folder

Hello Pete,
I 've done this already. I found that as soon as I select a
file using OpenFileDialog the folder is 'occupied' by my app.
Independ if I delete the object OpenFileDialog after using it.
Later on I proceed the files and delete them all, so that I
have an empty folder.
I also set the current directory to another one or to the parent directory of the one to be deleted (using the API functions)- no success.
When I hold my app at a braekpoint I also can not remove the
folder using the explorer even if it is empty. I have to terminate my app. There must be something with rights mangement
under WinXP.
Best regards and thanks
Roland
"Pete Fraser" < XXXX@XXXXX.COM >wrote:
Quote
Something in your app must be using that directory.
Perhaps you can step through it and try to delete the directory from File
Explorer. What's in the directory?

Rgds Pete

"Roland" < XXXX@XXXXX.COM >wrote in message
news:4039fbf3$ XXXX@XXXXX.COM ...
>
>Hello Pete,
>
>...it's unbelievable persistent. I altered the current dir using
'SetCurrentDirectory()' and checked it afterwards with
'GetCurrentdirectory()' but RemoveDir fails.
>
>I build a workaround using a batch file that starts an exe which is then
erasing the folder. That works. If I run the exe from my app it don't work.
I have to terminate my app before I can do it. It's very mysterious!


 

Re:Problems to remove a folder

Have you checked the NoChangeDir property for the OpenDialog.
Help says:
"ofNoChangeDir After the user clicks OK, resets the current directory to
whatever it was before the file-selection dialog opened."
So that may do it.
HTH Pete
"Roland" < XXXX@XXXXX.COM >wrote in message
Quote

Hello Pete,

I 've done this already. I found that as soon as I select a
file using OpenFileDialog the folder is 'occupied' by my app.
Independ if I delete the object OpenFileDialog after using it.
Later on I proceed the files and delete them all, so that I
have an empty folder.

I also set the current directory to another one or to the parent directory
of the one to be deleted (using the API functions)- no success.


When I hold my app at a braekpoint I also can not remove the
folder using the explorer even if it is empty. I have to terminate my app.
There must be something with rights mangement
under WinXP.

Best regards and thanks

Roland



"Pete Fraser" < XXXX@XXXXX.COM >wrote:
>Something in your app must be using that directory.
>Perhaps you can step through it and try to delete the directory from File
>Explorer. What's in the directory?
>
>Rgds Pete
>
>"Roland" < XXXX@XXXXX.COM >wrote in message
>news:4039fbf3$ XXXX@XXXXX.COM ...
>>
>>Hello Pete,
>>
>>...it's unbelievable persistent. I altered the current dir using
>'SetCurrentDirectory()' and checked it afterwards with
>'GetCurrentdirectory()' but RemoveDir fails.
>>
>>I build a workaround using a batch file that starts an exe which is
then
>erasing the folder. That works. If I run the exe from my app it don't
work.
>I have to terminate my app before I can do it. It's very mysterious!
>
>

 

Re:Problems to remove a folder

Hello Pete,
I tested it but it doesn't help too. It happens on Win NT too.
BR
Roland
"Pete Fraser" < XXXX@XXXXX.COM >wrote:
Quote
Have you checked the NoChangeDir property for the OpenDialog.
Help says:
"ofNoChangeDir After the user clicks OK, resets the current directory to
whatever it was before the file-selection dialog opened."
So that may do it.
HTH Pete

"Roland" < XXXX@XXXXX.COM >wrote in message
news:403a1517$ XXXX@XXXXX.COM ...
>
>Hello Pete,
>
>I 've done this already. I found that as soon as I select a
>file using OpenFileDialog the folder is 'occupied' by my app.
>Independ if I delete the object OpenFileDialog after using it.
>Later on I proceed the files and delete them all, so that I
>have an empty folder.
>
>I also set the current directory to another one or to the parent directory
of the one to be deleted (using the API functions)- no success.
>
>
>When I hold my app at a braekpoint I also can not remove the
>folder using the explorer even if it is empty. I have to terminate my app.
There must be something with rights mangement
>under WinXP.
>
>Best regards and thanks
>
>Roland
>
>
>
>"Pete Fraser" < XXXX@XXXXX.COM >wrote:
>>Something in your app must be using that directory.
>>Perhaps you can step through it and try to delete the directory from File
>>Explorer. What's in the directory?
>>
>>Rgds Pete
>>
>>"Roland" < XXXX@XXXXX.COM >wrote in message
>>news:4039fbf3$ XXXX@XXXXX.COM ...
>>>
>>>Hello Pete,
>>>
>>>...it's unbelievable persistent. I altered the current dir using
>>'SetCurrentDirectory()' and checked it afterwards with
>>'GetCurrentdirectory()' but RemoveDir fails.
>>>
>>>I build a workaround using a batch file that starts an exe which is
then
>>erasing the folder. That works. If I run the exe from my app it don't
work.
>>I have to terminate my app before I can do it. It's very mysterious!
>>
>>
>


 

Re:Problems to remove a folder

Hi Roland,
This code works on Windows XP
I have a form with two buttons, Button1 exhibits the behaviour that you are
seeing, Button2 works OK and allows the directory to be deleted. Note that
the "SetCurrentDir()" allows the directory to be deleted
If you want I can email the full project to you - just email me directly
(removed unwanted bits from my email)
HTH Pete
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName);
OpenDialog1->FileName = "";
OpenDialog1->Options =OpenDialog1->Options>>ofNoChangeDir;
OpenDialog1->Execute();
AnsiString FileName = OpenDialog1->FileName;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button2Click(TObject *Sender)
{
OpenDialog1->Options =OpenDialog1->Options<<ofNoChangeDir;
OpenDialog1->FileName = "";
OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName);
OpenDialog1->Execute();
AnsiString FileName = OpenDialog1->FileName;
SetCurrentDir(ExtractFilePath(Application->ExeName));
}
//--------------------------------------------------------------------------
-
"Roland" < XXXX@XXXXX.COM >wrote in message
Quote

Hello Pete,

I tested it but it doesn't help too. It happens on Win NT too.
 

Re:Problems to remove a folder

No, this code does NOT work. I have exactly the same problem as Roland.
Unless I quit the app and restart it, I cannot remove the directory. This
has started happening recently after upgrading to XP, so it is something to
do with the way XP caches objects that it has recently used. I'm wondering
whether the knowledgebase article at
support.microsoft.com/default.aspx has the
answer. The key phrase being "These registry entries will turn off the use
of opportunistic file locking and the caching of files previously open but
now closed".
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
XXXX@XXXXX.COM
"Pete Fraser" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Roland,
This code works on Windows XP
I have a form with two buttons, Button1 exhibits the behaviour that you
are
seeing, Button2 works OK and allows the directory to be deleted. Note that
the "SetCurrentDir()" allows the directory to be deleted
If you want I can email the full project to you - just email me directly
(removed unwanted bits from my email)

HTH Pete


//--------------------------------------------------------------------------
-

void __fastcall TForm1::Button1Click(TObject *Sender)
{
OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName);
OpenDialog1->FileName = "";
OpenDialog1->Options =OpenDialog1->Options>>ofNoChangeDir;
OpenDialog1->Execute();
AnsiString FileName = OpenDialog1->FileName;
}

//--------------------------------------------------------------------------
-

void __fastcall TForm1::Button2Click(TObject *Sender)
{
OpenDialog1->Options =OpenDialog1->Options<<ofNoChangeDir;
OpenDialog1->FileName = "";
OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName);
OpenDialog1->Execute();
AnsiString FileName = OpenDialog1->FileName;
SetCurrentDir(ExtractFilePath(Application->ExeName));
}

//--------------------------------------------------------------------------
-

"Roland" < XXXX@XXXXX.COM >wrote in message
news:403b2c1c$ XXXX@XXXXX.COM ...
>
>Hello Pete,
>
>I tested it but it doesn't help too. It happens on Win NT too.


 

Re:Problems to remove a folder

Well I'm sorry guys, but it worked on my system without any problem. One
button locked the directory, the other didn't, so there must be some
difference in your version of XP.
I have all the latest patches/SPs so I don't understand what the problem can
be.
I'll just have to leave it to you. When you find the answer, please report
back here so that we can all benefit.
Rgds Pete
"Mark Jacobs" < XXXX@XXXXX.COM >wrote in message
Quote
No, this code does NOT work. I have exactly the same problem as Roland.
Unless I quit the app and restart it, I cannot remove the directory. This
has started happening recently after upgrading to XP, so it is something
to
do with the way XP caches objects that it has recently used. I'm wondering
whether the knowledgebase article at
support.microsoft.com/default.aspx has the
answer. The key phrase being "These registry entries will turn off the use
of opportunistic file locking and the caching of files previously open but
now closed".