BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RemoveDir doesn't work with W2000 and XP but under W98

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Jochen Kunze
Guest





PostPosted: Mon Jan 12, 2004 4:17 pm    Post subject: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote



Hi,
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

With "RemoveDirectory" it's nearly the same. In some messages posted
in this group I found that findclose must be executed after findfirst
and findnext (that isn't relevant to this short peace of code) and
that the current directory may not be the one that you want to delete.
So I inserted the SetCurrentDirectory with a target far far away.
When I try deaper or flatter structures of directories, it isn't
regular what happens. The result seems to be random and almost in
every case some folders aren't deleted.
Sometimes there seems to be a connection to which folder is marked up
in the explorer during runtime, but I tested that not quiet often.
I'm logged in as an admin to the system, so that normaly the program
must have the permission to delete.

Does anybody knows something about this problem. I'm very happy about
every little hint!
Back to top
Kent Briggs
Guest





PostPosted: Mon Jan 12, 2004 6:50 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote



Jochen Kunze wrote:

Quote:
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

Try setting to the root of drive you are working with and see if that
makes a difference:

SetCurrentDir('g:');
RemoveDir('g:Zielv1v2v3');
RemoveDir('g:Zielv1v2');
RemoveDir('g:Zielv1');

--
Kent Briggs, [email]kbriggs (AT) spamcop (DOT) net[/email]
Briggs Softworks, http://www.briggsoft.com


Back to top
Tom de Neef
Guest





PostPosted: Mon Jan 12, 2004 10:04 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote



"Jochen Kunze" <mail (AT) gude (DOT) info> wrote

Quote:
Hi,
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

With "RemoveDirectory" it's nearly the same. In some messages posted
in this group I found that findclose must be executed after findfirst
and findnext (that isn't relevant to this short peace of code) and
that the current directory may not be the one that you want to delete.
So I inserted the SetCurrentDirectory with a target far far away.
When I try deaper or flatter structures of directories, it isn't
regular what happens. The result seems to be random and almost in
every case some folders aren't deleted.
Sometimes there seems to be a connection to which folder is marked up
in the explorer during runtime, but I tested that not quiet often.
I'm logged in as an admin to the system, so that normaly the program
must have the permission to delete.

Does anybody knows something about this problem. I'm very happy about
every little hint!

I posted a similar question last week. I'm using W2k. Responses convinced me
it has nothing to do with Delphi. Only way around it I found is to remove
the next time I start the application - I then check for empty subdirs that
I tried to remove. It will always remove then. So, I guess, it does have
something to do with the findFirst, etc calling and the removal of the files
in these dirs.
Tom




Back to top
Aaron Miles
Guest





PostPosted: Mon Jan 12, 2004 10:46 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

Windows 2000 and windows xp have a hidden file they put into the directories
for use as thumb nail viewer and the likes. Because of
the previous use is why the folder has not been deleted. It sucks but thats
life. Why not throw the directories into the recycle bin
that will work.

Thanks

Aaron

"Jochen Kunze" <mail (AT) gude (DOT) info> wrote

Quote:
Hi,
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

With "RemoveDirectory" it's nearly the same. In some messages posted
in this group I found that findclose must be executed after findfirst
and findnext (that isn't relevant to this short peace of code) and
that the current directory may not be the one that you want to delete.
So I inserted the SetCurrentDirectory with a target far far away.
When I try deaper or flatter structures of directories, it isn't
regular what happens. The result seems to be random and almost in
every case some folders aren't deleted.
Sometimes there seems to be a connection to which folder is marked up
in the explorer during runtime, but I tested that not quiet often.
I'm logged in as an admin to the system, so that normaly the program
must have the permission to delete.

Does anybody knows something about this problem. I'm very happy about
every little hint!



Back to top
Jochen Kunze
Guest





PostPosted: Tue Jan 13, 2004 8:34 am    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

[email]mail (AT) gude (DOT) info[/email] (Jochen Kunze) wrote in message news:<103d3a04.0401120817.25d99fb9 (AT) posting (DOT) google.com>...
I've forgotten to say that:
When I try GetLastError I get:
ERROR_FILE_NOT_FOUND, although the folder exists or
ERROR_DIR_NOT_EMPTY, although it is empty
ERROR_SHARING_VIOLATION, although I don't know which process works
with that directory
Back to top
Jochen Kunze
Guest





PostPosted: Tue Jan 13, 2004 8:41 am    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

Kent Briggs <kbriggs (AT) spamcop (DOT) net> wrote

Quote:
Jochen Kunze wrote:

I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

Try setting to the root of drive you are working with and see if that
makes a difference:

SetCurrentDir('g:');
RemoveDir('g:Zielv1v2v3');
RemoveDir('g:Zielv1v2');
RemoveDir('g:Zielv1');


Thanks for your hint! I've tried it. But I get ERROR_DIR_NOT_EMPTY and
ERROR_FILE_NOT_FOUND and some directories aren't deleted.

Back to top
Jochen Kunze
Guest





PostPosted: Tue Jan 13, 2004 11:47 am    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote

Quote:
"Jochen Kunze" <mail (AT) gude (DOT) info> wrote in message
news:103d3a04.0401120817.25d99fb9 (AT) posting (DOT) google.com...
Hi,
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

With "RemoveDirectory" it's nearly the same. In some messages posted
in this group I found that findclose must be executed after findfirst
and findnext (that isn't relevant to this short peace of code) and
that the current directory may not be the one that you want to delete.
So I inserted the SetCurrentDirectory with a target far far away.
When I try deaper or flatter structures of directories, it isn't
regular what happens. The result seems to be random and almost in
every case some folders aren't deleted.
Sometimes there seems to be a connection to which folder is marked up
in the explorer during runtime, but I tested that not quiet often.
I'm logged in as an admin to the system, so that normaly the program
must have the permission to delete.

Does anybody knows something about this problem. I'm very happy about
every little hint!

I posted a similar question last week. I'm using W2k. Responses convinced me
it has nothing to do with Delphi. Only way around it I found is to remove
the next time I start the application - I then check for empty subdirs that
I tried to remove. It will always remove then. So, I guess, it does have
something to do with the findFirst, etc calling and the removal of the files
in these dirs.
Tom

Hi Tom,
I've tried to use FindFirst, FindNext and FindClose and to delete the
files found with this little piece of code:

if (FindFirst('g:Zielv1v2v3v4*.*', faAnyFile, found) = 0) then
begin
writeln('Deleted File: ' + found.Name);
DeleteFile('g:Zielv1v2v3v4' + (found.Name));
DeletedFiles := DeletedFiles + 1;
while (FindNext(found) = 0) do
begin
writeln('Deleted File: ' + found.Name);
DeleteFile('g:Zielv1v2v3v4' + (found.Name));
DeletedFiles := DeletedFiles + 1
end;
end;
FindClose(found);

SetCurrentDir('c:');
removeDirectory('g:Zielv1v2v3v4');
Write('Error Removing ' + 'g:Zielv1v2v3v4: ');
Writeln(GetLastError());

and so on for all v-Directories. The output was:

Deleted File: .
Deleted File: ..
Deleted File: v5
Error Removing g:Zielv1v2v3v4: 145
Deleted File: .
Deleted File: ..
Deleted File: v4
Error Removing g:Zielv1v2v3: 145
Deleted File: .
Deleted File: ..
Deleted File: v3
Error Removing g:Zielv1v2: 145
Deleted File: .
Deleted File: ..
Deleted File: v2
Error Removing g:Zielv1: 145
12

And no directorie was deleted. The Errors seem to be random. Sometimes
it's "The system cannot find the path specified". 145 by the way is
"The directory is not empty." Does someone know what's a '.' or
'..'-file is?

Back to top
Tom de Neef
Guest





PostPosted: Tue Jan 13, 2004 12:59 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote


"Jochen Kunze" <mail (AT) gude (DOT) info> wrote

Quote:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote

"Jochen Kunze" <mail (AT) gude (DOT) info> wrote in message
news:103d3a04.0401120817.25d99fb9 (AT) posting (DOT) google.com...

Does someone know what's a '.' or '..'-file is?

They are references to the current dir or its parent.
I.e. "..*.*" would indicate all files in the parent directory.
Why they show up with FindFirst I do not understand. I checked if anything
changed when excluding these from the delete instruction, but found no
difference.

Tom



Back to top
Tom de Neef
Guest





PostPosted: Tue Jan 13, 2004 1:00 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

Quote:
Aaron Miles" <aaron (AT) noSpammerPLEASEqbdthebookshop (DOT) com> wrote

Windows 2000 and windows xp have a hidden file they put into the
directories
for use as thumb nail viewer and the likes. Because of
the previous use is why the folder has not been deleted. It sucks but
thats
life. Why not throw the directories into the recycle bin
that will work.

Thanks

Aaron


What statement would you use to accomplish a move to the recycle bin ?
Tom



Back to top
Bruce Roberts
Guest





PostPosted: Tue Jan 13, 2004 11:54 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote


"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote


Quote:
They are references to the current dir or its parent.
I.e. "..*.*" would indicate all files in the parent directory.
Why they show up with FindFirst I do not understand. I checked if anything
changed when excluding these from the delete instruction, but found no
difference.

These calls go back to the days of DOS as do '.' and '..'. One of the
problems with systems is that it is much harder to throw something out than
to introduce new features. So Windows 2003 lives with a lot of baggage from
Windows 1.0 which itself had to support MS-DOS (because it lived on-top of
it).

Both . and .. are virtual entries and are not real entries in the directory.



Back to top
Bruce Roberts
Guest





PostPosted: Tue Jan 13, 2004 11:55 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote


"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote


Quote:
What statement would you use to accomplish a move to the recycle bin ?

shFileOperation



Back to top
Duncan Murdoch
Guest





PostPosted: Wed Jan 14, 2004 2:00 am    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

On Tue, 13 Jan 2004 18:54:14 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> wrote:

Quote:
Both . and .. are virtual entries and are not real entries in the directory.

Actually, they are real entries in the FAT-based file systems. I
don't know about NTFS.

Duncan Murdoch

Back to top
Maarten Wiltink
Guest





PostPosted: Wed Jan 14, 2004 9:13 am    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

"Duncan Murdoch" <dmurdoch (AT) pair (DOT) com> wrote

Quote:
On Tue, 13 Jan 2004 18:54:14 -0500, "Bruce Roberts"
[email]ber (AT) bounceitattcanada (DOT) xnet[/email]> wrote:

Both . and .. are virtual entries and are not real entries in the
directory.

Actually, they are real entries in the FAT-based file systems. I
don't know about NTFS.

They were real entries, but you couldn't delete them. Nor did you
have to in order to delete the directory containing them. (Not that
this helps the current discussion any, of course.)

In at least some Novell _clients_, it was configurable if you wanted
to see current & parent directory entries.

Groetjes,
Maarten Wiltink



Back to top
Kent Briggs
Guest





PostPosted: Wed Jan 14, 2004 4:02 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

Duncan Murdoch wrote:

Quote:
Actually, they are real entries in the FAT-based file systems. I
don't know about NTFS.

Correct, the only physical "." record in NTFS is the root directory,
$MFT inode 5 to be exact. :-)

--
Kent Briggs, [email]kbriggs (AT) spamcop (DOT) net[/email]
Briggs Softworks, http://www.briggsoft.com


Back to top
J French
Guest





PostPosted: Thu Jan 15, 2004 12:47 pm    Post subject: Re: RemoveDir doesn't work with W2000 and XP but under W98 Reply with quote

Bottom posted :-

On 13 Jan 2004 03:47:20 -0800, [email]mail (AT) gude (DOT) info[/email] (Jochen Kunze) wrote:

Quote:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> wrote

"Jochen Kunze" <mail (AT) gude (DOT) info> wrote in message
news:103d3a04.0401120817.25d99fb9 (AT) posting (DOT) google.com...
Hi,
I want to use RemoveDir or RemoveDirectory in my project. With W98 it
works fine, but with W2000 or XP the function randomly doesn't delete
some empty folders.
e.g. the following code deletes v3 and v2 but not v1.

SetCurrentDir('c:');
RemoveDir('g:Zielv1v2v3');
SetCurrentDir('c:');
RemoveDir('g:Zielv1v2');
SetCurrentDir('c:');
RemoveDir('g:Zielv1');

With "RemoveDirectory" it's nearly the same. In some messages posted
in this group I found that findclose must be executed after findfirst
and findnext (that isn't relevant to this short peace of code) and
that the current directory may not be the one that you want to delete.
So I inserted the SetCurrentDirectory with a target far far away.
When I try deaper or flatter structures of directories, it isn't
regular what happens. The result seems to be random and almost in
every case some folders aren't deleted.
Sometimes there seems to be a connection to which folder is marked up
in the explorer during runtime, but I tested that not quiet often.
I'm logged in as an admin to the system, so that normaly the program
must have the permission to delete.

Does anybody knows something about this problem. I'm very happy about
every little hint!

I posted a similar question last week. I'm using W2k. Responses convinced me
it has nothing to do with Delphi. Only way around it I found is to remove
the next time I start the application - I then check for empty subdirs that
I tried to remove. It will always remove then. So, I guess, it does have
something to do with the findFirst, etc calling and the removal of the files
in these dirs.
Tom

Hi Tom,
I've tried to use FindFirst, FindNext and FindClose and to delete the
files found with this little piece of code:

if (FindFirst('g:Zielv1v2v3v4*.*', faAnyFile, found) = 0) then
begin
writeln('Deleted File: ' + found.Name);
DeleteFile('g:Zielv1v2v3v4' + (found.Name));
DeletedFiles := DeletedFiles + 1;
while (FindNext(found) = 0) do
begin
writeln('Deleted File: ' + found.Name);
DeleteFile('g:Zielv1v2v3v4' + (found.Name));
DeletedFiles := DeletedFiles + 1
end;
end;
FindClose(found);

SetCurrentDir('c:');
removeDirectory('g:Zielv1v2v3v4');
Write('Error Removing ' + 'g:Zielv1v2v3v4: ');
Writeln(GetLastError());

and so on for all v-Directories. The output was:

Deleted File: .
Deleted File: ..
Deleted File: v5
Error Removing g:Zielv1v2v3v4: 145
Deleted File: .
Deleted File: ..
Deleted File: v4
Error Removing g:Zielv1v2v3: 145
Deleted File: .
Deleted File: ..
Deleted File: v3
Error Removing g:Zielv1v2: 145
Deleted File: .
Deleted File: ..
Deleted File: v2
Error Removing g:Zielv1: 145
12

And no directorie was deleted. The Errors seem to be random. Sometimes
it's "The system cannot find the path specified". 145 by the way is
"The directory is not empty." Does someone know what's a '.' or
'..'-file is?

I think that this is because FindFirst is still active

- you would be better off writing the full names to a temporary file
- then using FindClose
- and then zapping the files and directories



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.