Article Preview
Buy Now
FEATURE
Delete It!
Delete that pesky file or folder that's being stubborn
Issue: 15.6 (November/December 2017)
Author: Sam Rowlands
Author Bio: Sam is a pixelMancer and codeWeaver at Ohanaware.
Article Description: n>No description availabl
Article Length (in bytes): 15,463
Starting Page Number: r>
Article Number: 15603
Related Link(s): None
Excerpt of article text...
Deleting files and folders should be an easy task right? Call
folderitem.delete
and the job's done.Yes, that's the
principle , but as more and more background system daemons prod, poke, inspect and sometimes open the files as you're working on them,folderitem.delete
can fail. I suspect that a common cause of this is to do with how Apple's APIs work.For instance, if you're reading an image file, it's not closed until you explicitly destroy the object that's reading the file, which leads me to believe that many of Apple's modern daemons encounter an error and just abandon the routine, leaving the file handler still open.
Then, there are folders. These need to have all the files deleted first, and if one of those files is in use by an annoying background task, you can't delete that folder.
What about offering the user the option of being able to recover the file from the Trash?
After working with video and finding that these often get tied up by system daemons ("Exporting failed because it couldn't replace or delete the specified file."), I got fed up and decided I was going to create a single function that I could use to obliterate files when I needed to do so.
...End of Excerpt. Please purchase the magazine to read the full article.