 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dodgy Guest
|
Posted: Tue Jan 13, 2004 1:26 am Post subject: Deleting files - opinion required... |
|
|
My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
Option 1 is slower, but I can trap the problem delete and keep going,
flagging any files that refuse to go for later user action.
So, have I missed anything, or are they the only options?
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Kent Briggs Guest
|
Posted: Tue Jan 13, 2004 2:25 am Post subject: Re: Deleting files - opinion required... |
|
|
Dodgy wrote:
| Quote: | My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster,
|
You can speed up Option 1 by setting the right flags. Here's what I
use in File Maven Pro:
function RecycleFile(fname: string): boolean;
var
Struct: TSHFileOpStruct;
begin
fillchar(struct,sizeof(struct),0);
Struct.wnd:=application.handle;
Struct.WFunc:=FO_DELETE;
Struct.pFrom:=pchar(expandfilename(fname)+#0);
Struct.pTo:=nil;
Struct.fFlags:=FOF_SILENT or FOF_NOCONFIRMATION or FOF_ALLOWUNDO;
Struct.fAnyOperationsAborted:=false;
Struct.hNameMappings:=nil;
result:=ShFileOperation(Struct)=0;
end;
--
Kent Briggs, [email]kbriggs (AT) spamcop (DOT) net[/email]
Briggs Softworks, http://www.briggsoft.com
|
|
| Back to top |
|
 |
Jeremy Collins Guest
|
Posted: Tue Jan 13, 2004 8:22 am Post subject: Re: Deleting files - opinion required... |
|
|
Dodgy wrote:
| Quote: | My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
Option 1 is slower, but I can trap the problem delete and keep going,
flagging any files that refuse to go for later user action.
So, have I missed anything, or are they the only options?
|
I take it you've already built the list of files with FindFirst /
FindNext. How long does it take loop through the list, simply trying to
open and close each file? If that's relatively quick, you could remove
files in use from your delete list (and build a list of currently
undeletable files to inform the user). Use option 2 on your refined
list.
Or you could perform your cleanup routine in a background thread. Remove
the files from the list if they are successfully deleted, and make the
remaining list persist between sessions of your application. The app
would continue trying to delete files the next time it is started.
--
jc
Remove the -not from email
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Wed Jan 14, 2004 12:38 am Post subject: Re: Deleting files - opinion required... |
|
|
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote
| Quote: | My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
Option 1 is slower, but I can trap the problem delete and keep going,
flagging any files that refuse to go for later user action.
So, have I missed anything, or are they the only options?
|
A hybrid approach. Attempt to delete x files at a time. When that doesn't
work, try x - n || n > 0 files. A recursive routine could be used if one
passed in the list of files, a return list of failures, and a value for x. A
slightly different approach would be to go through the list deleting x at a
time. Then rebuild the list and delete file at a time.
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Wed Jan 14, 2004 1:50 pm Post subject: Re: Deleting files - opinion required... |
|
|
On Tue, 13 Jan 2004 19:38:22 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> waffled on about something:
| Quote: |
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote in message
news:q0i6001hlqf56os0i1ppql4q1c81t3gnvh (AT) 4ax (DOT) com...
My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
Option 1 is slower, but I can trap the problem delete and keep going,
flagging any files that refuse to go for later user action.
So, have I missed anything, or are they the only options?
A hybrid approach. Attempt to delete x files at a time. When that doesn't
work, try x - n || n > 0 files. A recursive routine could be used if one
passed in the list of files, a return list of failures, and a value for x. A
slightly different approach would be to go through the list deleting x at a
time. Then rebuild the list and delete file at a time.
|
Hi Bruce, thanks for your suggestion. Sounds good. I'll give that a
try.
I think I'm going to have to try a couple of different methods and
benchmark them to try and get best performance.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Marco van de Voort Guest
|
Posted: Wed Feb 04, 2004 12:35 am Post subject: Re: Deleting files - opinion required... |
|
|
On 2004-01-13, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
| Quote: | My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
|
These operations are filesystem driver (Fat32, ntfs) dependant. Which filesystem do
you use?
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Wed Feb 04, 2004 9:58 am Post subject: Re: Deleting files - opinion required... |
|
|
On Wed, 4 Feb 2004 00:35:07 +0000 (UTC), Marco van de Voort
<marcov (AT) stack (DOT) nl> waffled on about something:
| Quote: | On 2004-01-13, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
These operations are filesystem driver (Fat32, ntfs) dependant. Which filesystem do
you use?
|
All of them!
I don't believe SHFileOperation is FS dependant though... I've used
the same code on everything from 95 to XP using FAT16 to the latest
NTFS
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Catherine Rees Lay Guest
|
Posted: Wed Feb 04, 2004 2:06 pm Post subject: Re: Deleting files - opinion required... |
|
|
In article <kfg120pujl2bctke7oc6vubssaeq74m3jc (AT) 4ax (DOT) com>, Dodgy
<Dodgy (AT) earth (DOT) planet.universe> writes
| Quote: | On Wed, 4 Feb 2004 00:35:07 +0000 (UTC), Marco van de Voort
[email]marcov (AT) stack (DOT) nl[/email]> waffled on about something:
On 2004-01-13, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
My app has a lot of user files to delete, with the option of deleting
to the recycle bin... Now I can think of two ways to do this...
1) Use the SHFileOperation for each file, one at a time.
2) Build a huge list and feed them all into SHFileOperation in one
go...
Now here's the problem... Option 2 is far faster, *but* and it's a big
but, if windows hit's a file it can't delete (locked, read only etc),
the whole delete stops.
These operations are filesystem driver (Fat32, ntfs) dependant. Which
filesystem do
you use?
All of them!
I don't believe SHFileOperation is FS dependant though... I've used
the same code on everything from 95 to XP using FAT16 to the latest
NTFS
Dodgy.
|
How often is it likely to occur? If the answer is "almost never", use
option 2, then check for the presence of the last file in the list, if
it's there, do it all again with option 1 instead (or you could do some
sort of binary search in the list to find roughly where the mass delete
stopped). But, as a rule of thumb, try not to make your program majorly
slow in all cases if it only needs to be in 1% of them.
If it's "quite often" I'll leave it to the filesystem experts to answer
:-)
HTH,
Catherine.
--
Catherine Rees Lay
To email me, use my first name in front of the "at".
|
|
| Back to top |
|
 |
Marco van de Voort Guest
|
Posted: Sat Feb 07, 2004 1:53 pm Post subject: Re: Deleting files - opinion required... |
|
|
On 2004-02-04, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
| Quote: | On Wed, 4 Feb 2004 00:35:07 +0000 (UTC), Marco van de Voort
[email]marcov (AT) stack (DOT) nl[/email]> waffled on about something:
On 2004-01-13, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
you use?
All of them!
I don't believe SHFileOperation is FS dependant though... I've used
the same code on everything from 95 to XP using FAT16 to the latest
NTFS
|
I meant which one is optimal. NTFS stores dir entries in a bintree, and
FAT linearly IIRC.
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Sat Feb 07, 2004 3:35 pm Post subject: Re: Deleting files - opinion required... |
|
|
"Marco van de Voort" <marcov (AT) stack (DOT) nl> wrote
| Quote: | On 2004-02-04, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
|
[...]
| Quote: | I don't believe SHFileOperation is FS dependant though... I've used
the same code on everything from 95 to XP using FAT16 to the latest
NTFS
I meant which one is optimal. NTFS stores dir entries in a bintree,
and FAT linearly IIRC.
|
YRC. But the usual method of deleting directory entries with FAT is
to overwrite the first character of the 8.3 name with #$e5. (If this
was the actual first character of the name, it was stored as #$05,
which wasn't a valid character in filenames.)
So unless the filesystem driver immediately compacts the directory,
which I've never seen, deleting an entry is a constant-time operation.
That does not include locating the entry, which is linear-time.
Does NTFS allow for keeping deleted directory entries in a minimally-
disturbed state? It seems likely; OTOH there is Microsoft's famous
statement that NTFS "does not fragment!"
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Marco van de Voort Guest
|
Posted: Sun Feb 08, 2004 11:46 pm Post subject: Re: Deleting files - opinion required... |
|
|
On 2004-02-07, Maarten Wiltink <maarten (AT) kittensandcats (DOT) net> wrote:
| Quote: | "Marco van de Voort" <marcov (AT) stack (DOT) nl> wrote in message
news:slrnc29rf7.p3e.marcov (AT) toad (DOT) stack.nl...
On 2004-02-04, Dodgy <Dodgy (AT) earth (DOT) planet.universe> wrote:
[...]
I don't believe SHFileOperation is FS dependant though... I've used
the same code on everything from 95 to XP using FAT16 to the latest
NTFS
I meant which one is optimal. NTFS stores dir entries in a bintree,
and FAT linearly IIRC.
YRC. But the usual method of deleting directory entries with FAT is
to overwrite the first character of the 8.3 name with #$e5. (If this
was the actual first character of the name, it was stored as #$05,
which wasn't a valid character in filenames.)
So unless the filesystem driver immediately compacts the directory,
which I've never seen, deleting an entry is a constant-time operation.
That does not include locating the entry, which is linear-time.
|
On FAT, but not on NTFS afaik.
| Quote: | Does NTFS allow for keeping deleted directory entries in a minimally-
disturbed state? It seems likely;
|
IIRC no, this is all in the MFT, and IIRC there is only a counter of
entries. A few entries can be stored locally, for the rest a new block in
the MFT is allocated.
| Quote: | OTOH there is Microsoft's famous statement that NTFS "does not fragment!"
|
That is more Data, not filesystem data. And of course does not fragment is
_really_ bold (and unoptimal even).
NTFS does fragment, but to a much lesser degree. Moreover you can plug in
additional drivers (diskkeeper) that avoid even more fragmentation.
|
|
| 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
|
|