Fast file deleting


I wanted to delete a 450GB archive from a network drive (Seagate Central) without reformatting the drive. I tried 3 ways:
(1) straight from the finder,
(2) a recursive delete routine (pasted in at the end) that I think I picked up on the NUG,
(3) From the terminal - sudo rm -rf /Directory_to_delete.

They all took an age:
(1) seemed to choke after counting around 2 million files and never got to the point of deleting anything.
(2) worked away and might delete 20 or so files in a minute for several hours, but then it seemed to slow and do less and less and I felt I had to crash it out. I called it from a thread, passing the parent directory to start if off. Every few seconds I’d read DelCount which was an Integer on the Window and display it for signs of life.
(3) Chugged away and eventually - three and a half days later - the backup was deleted.

Three and a half days! OK, it worked from the terminal but I’d imagined it would be way quicker. Any advice how I ought to have approached this?

Many thanks - Richard.

[code]Sub RecursiveDelete(f as FolderItem)

Dim i, c as Integer

if f=nil or f.exists=false then

if then //it’s a folder
c = f.count
for i= c downto 1 //go through each item
if c=0 then
f.locked = false
DelCount = DelCount+1
f.locked = false
DelCount = DelCount+1

End Sub

Looks like a quick format ought to take less than 3 1/2 days :wink:

A nice article…
Looks like the Perl method is very fast, or the xargs method in the comments…

this should be very fast… it uses xargs to group the files into the largest argument list allowed to rm, then you can delete the empty folders

find /Directory_to_delete -type f -print0 | xargs -0 rm -f
rm -rf /Directory_to_delete

I would think the Xojo code you posted would be far faster if you did a count on the directory structure, redim an array to hold the folderitems, then recurse through the structure and populate the array. Once you have the array, you could work backwards from the deepest item up until the structure is gone…

Also, you’re using downto to loop through the folderitems, and calling trueitem each time through the loop… that’s a very slow method… try replacing it with this (approximately)

dim folders() as folderitem dim count as integer=f.count redim folders(count-1) for i as integer=1 to count folders(i-1)=f.trueitem(i) next
Should be infinitely faster than the loop above