 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tom de Neef Guest
|
Posted: Wed Jan 07, 2004 10:35 am Post subject: RemoveDir |
|
|
I know this has been posted before - but I can't find what I need.
1) remove all files from subDir, using FindFirst, FindNext
2) make sure current dir is elsewhere, using SetCurrentDir
3) if RemoveDir(subDir) then I am pleased
But I am not pleased, since the RemoveDir returns FALSE.
Upon restart of the app:
a) check if subDir is empty, using FindFirst
b) if RemoveDir(subDir) then I am pleased
and now I am pleased.
What stops the RemoveDir in step 3 above ? How should I cope?
Tom
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Wed Jan 07, 2004 12:00 pm Post subject: Re: RemoveDir |
|
|
On Wed, 7 Jan 2004 11:35:21 +0100, "Tom de Neef" <tdeneef (AT) qolor (DOT) nl>
wrote:
| Quote: | I know this has been posted before - but I can't find what I need.
1) remove all files from subDir, using FindFirst, FindNext
and FindClose ?
2) make sure current dir is elsewhere, using SetCurrentDir
what does SetCurrentDir return ?
3) if RemoveDir(subDir) then I am pleased
But I am not pleased, since the RemoveDir returns FALSE.
|
I can imagine that you are very annoyed
| Quote: |
Upon restart of the app:
a) check if subDir is empty, using FindFirst
b) if RemoveDir(subDir) then I am pleased
and now I am pleased.
What stops the RemoveDir in step 3 above ? How should I cope?
|
Try this :-
procedure TForm1.Button1Click(Sender: TObject);
Const TheDir :String = 'c:t';
Const OtherDir :String = 'c:naff';
Var
Res :LongBool;
begin
Res := SetCurrentDirectory( PChar(OtherDir) );
If Res = False Then
ShowMessage( SysErrorMessage( GetLastError ) );
Res := RemoveDirectory( PChar(TheDir) );
If Res = False Then
ShowMessage( SysErrorMessage( GetLastError ) );
end;
|
|
| Back to top |
|
 |
Andreas Schmidt Guest
|
Posted: Wed Jan 07, 2004 12:06 pm Post subject: Re: RemoveDir |
|
|
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> schrieb im Newsbeitrag
news:3ffbe1c6$0$330$e4fe514c (AT) news (DOT) xs4all.nl...
| Quote: | I know this has been posted before - but I can't find what I need.
1) remove all files from subDir, using FindFirst, FindNext
2) make sure current dir is elsewhere, using SetCurrentDir
3) if RemoveDir(subDir) then I am pleased
But I am not pleased, since the RemoveDir returns FALSE.
Upon restart of the app:
a) check if subDir is empty, using FindFirst
b) if RemoveDir(subDir) then I am pleased
and now I am pleased.
What stops the RemoveDir in step 3 above ? How should I cope?
|
Maybe some Explorer or IE proccess have a view on your "subDir" ?
To get detailed information try this:
if RemoveDir(somedirectory)=False then
RaiseLastWin32Error;
Andreas
|
|
| Back to top |
|
 |
Tom de Neef Guest
|
Posted: Wed Jan 07, 2004 12:43 pm Post subject: Re: RemoveDir |
|
|
"Andreas Schmidt" <a_j_schmidt (AT) rocketmail (DOT) com> wrote
| Quote: |
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> schrieb im Newsbeitrag
news:3ffbe1c6$0$330$e4fe514c (AT) news (DOT) xs4all.nl...
I know this has been posted before - but I can't find what I need.
1) remove all files from subDir, using FindFirst, FindNext
2) make sure current dir is elsewhere, using SetCurrentDir
3) if RemoveDir(subDir) then I am pleased
But I am not pleased, since the RemoveDir returns FALSE.
Upon restart of the app:
a) check if subDir is empty, using FindFirst
b) if RemoveDir(subDir) then I am pleased
and now I am pleased.
What stops the RemoveDir in step 3 above ? How should I cope?
Maybe some Explorer or IE proccess have a view on your "subDir" ?
To get detailed information try this:
if RemoveDir(somedirectory)=False then
RaiseLastWin32Error;
Andreas
|
Thanks. It appears that Windows detects that the subDir is still in use.
Must be by my app, even though it has successfully removed all its files and
the currentDir of the application is elsewhere.
I will force the removal upon the next restart of the app - a bit silly, but
it will do.
Tom
|
|
| Back to top |
|
 |
Alain Guest
|
Posted: Wed Jan 07, 2004 2:52 pm Post subject: Re: RemoveDir |
|
|
Hi,
I've noticed the same behaviour in Win2K's Explorer («It appears that
Windows detects that the subDir is still in use.») after emptying a
folder and then trying to remove the folder itself, so it might not be
«Must be by my app».
Alain
| Quote: | Thanks. It appears that Windows detects that the subDir is still in use.
Must be by my app, even though it has successfully removed all its files and
the currentDir of the application is elsewhere.
I will force the removal upon the next restart of the app - a bit silly, but
it will do.
Tom
|
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Wed Jan 07, 2004 8:06 pm Post subject: Re: RemoveDir |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | procedure TForm1.Button1Click(Sender: TObject);
Const TheDir :String = 'c:t';
Const OtherDir :String = 'c:naff';
Var
Res :LongBool;
begin
Res := SetCurrentDirectory( PChar(OtherDir) );
If Res = False Then
|
Pascal/Delphi has a built in Boolean type and understands boolean algebra
(unlike C). Comparing a boolean variable to a constant or literal is, IMO,
very poor practice in Delphi. I would suggest
if not Res then . . .
| Quote: | ShowMessage( SysErrorMessage( GetLastError ) );
Res := RemoveDirectory( PChar(TheDir) );
If Res = False Then
ShowMessage( SysErrorMessage( GetLastError ) );
end;
|
An alternative coding is
if not SetCurrentDirectory (pChar (OtherDir))
then ShowMessage (SysErrorMessage (GetLastError));
if not RenmoveDirectory (pChar (theDir))
then ShowMessage (SysErrorMessage (GetLastError));
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Wed Jan 07, 2004 8:07 pm Post subject: Re: RemoveDir |
|
|
"Andreas Schmidt" <a_j_schmidt (AT) rocketmail (DOT) com> wrote
| Quote: | if RemoveDir(somedirectory)=False then
RaiseLastWin32Error;
|
Comparing a Boolean result to a constant or literal is not, IMO, terribly
good practice in Delphi. A much better coding would be
if not RemoveDir (someDirectory) then . . .
|
|
| Back to top |
|
 |
Martin Harvey (Demon Acco Guest
|
Posted: Thu Jan 08, 2004 11:06 pm Post subject: Re: RemoveDir |
|
|
On Wed, 07 Jan 2004 14:52:50 GMT, Alain <Anibody (AT) anywhere (DOT) com> wrote:
| Quote: | Hi,
I've noticed the same behaviour in Win2K's Explorer («It appears that
Windows detects that the subDir is still in use.») after emptying a
folder and then trying to remove the folder itself, so it might not be
«Must be by my app».
Alain
|
There are a couple of unusual possibilities that may be the case:
- Open find first or find first notification handles?
- I beleive some directories can be used as templates or have stream
information attached to them?
MH.
|
|
| Back to top |
|
 |
VBDis Guest
|
Posted: Mon Jan 12, 2004 9:58 am Post subject: Re: RemoveDir |
|
|
Im Artikel <3ffbe1c6$0$330$e4fe514c (AT) news (DOT) xs4all.nl>, "Tom de Neef"
<tdeneef (AT) qolor (DOT) nl> schreibt:
| Quote: | 1) remove all files from subDir, using FindFirst, FindNext
|
Are you sure that FindClose is called afterwards?
DoDi
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Wed Jan 14, 2004 8:36 am Post subject: Re: RemoveDir |
|
|
On Wed, 7 Jan 2004 15:06:11 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> wrote:
| Quote: |
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3ffbf0ac.13199076 (AT) news (DOT) btclick.com...
procedure TForm1.Button1Click(Sender: TObject);
Const TheDir :String = 'c:t';
Const OtherDir :String = 'c:naff';
Var
Res :LongBool;
begin
Res := SetCurrentDirectory( PChar(OtherDir) );
If Res = False Then
Pascal/Delphi has a built in Boolean type and understands boolean algebra
(unlike C). Comparing a boolean variable to a constant or literal is, IMO,
very poor practice in Delphi. I would suggest
if not Res then . . .
ShowMessage( SysErrorMessage( GetLastError ) );
Res := RemoveDirectory( PChar(TheDir) );
If Res = False Then
ShowMessage( SysErrorMessage( GetLastError ) );
end;
An alternative coding is
if not SetCurrentDirectory (pChar (OtherDir))
then ShowMessage (SysErrorMessage (GetLastError));
if not RenmoveDirectory (pChar (theDir))
then ShowMessage (SysErrorMessage (GetLastError));
|
Actually I was deliberately breaking out the various steps to make
things very clear for the OP
Also, If ABool = False Then
is actually totally safe, as 'False' is unequivically Zero
- it is 'True' that is rather dangerous
- especially when returned from APIs
I'm not too keen on the : If Not ABool Then
construct, as it does not follow the way I think ...
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Thu Jan 15, 2004 3:37 pm Post subject: Re: RemoveDir |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | I'm not too keen on the : If Not ABool Then
construct, as it does not follow the way I think ...
|
I'm all for freedom of thought , but like natural language, I believe that
it is important to try and 'think' in the language when using it. This
allows for a more natural expression and hence better communications.
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Fri Jan 16, 2004 10:13 am Post subject: Re: RemoveDir |
|
|
On Thu, 15 Jan 2004 10:37:00 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> wrote:
| Quote: |
"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:4004fdb4.86161209 (AT) news (DOT) btclick.com...
I'm not too keen on the : If Not ABool Then
construct, as it does not follow the way I think ...
I'm all for freedom of thought , but like natural language, I believe that
it is important to try and 'think' in the language when using it. This
allows for a more natural expression and hence better communications.
|
I agree with that
- but my thought paths are sequential
eg: get a result, look at it, do something
The preceding 'Not' grates on me
To me, the ideal is for code to read like English
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Fri Jan 16, 2004 7:57 pm Post subject: Re: RemoveDir |
|
|
"J French" <erewhon (AT) nowhere (DOT) com> wrote
| Quote: | "J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:4004fdb4.86161209 (AT) news (DOT) btclick.com...
I'm not too keen on the : If Not ABool Then
construct, as it does not follow the way I think ...
[...]
- but my thought paths are sequential
eg: get a result, look at it, do something
The preceding 'Not' grates on me
To me, the ideal is for code to read like English
|
You should be writing Cobol, then.
$0000002b or (not $0000002b) - English enough for you?
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Fri Jan 16, 2004 10:49 pm Post subject: Re: RemoveDir |
|
|
"Maarten Wiltink" <maarten (AT) kittensandcats (DOT) net> wrote
| Quote: | $0000002b or (not $0000002b) - English enough for you?
|
lol
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|