I have a node to which I have a number of images attached through the usual content type image field mechanism. The attachment is done correctly, such that when I delete the node, the images are also deleted.
My problem is that these images are held in a subdirectory, which is not deleted by the file deletion process, and I end up with a bunch of empty and useless directories littering my file system. I tried deleting the directory with hook_node_delete()
, but this fails because Drupal hasn't yet gotten around to deleting the images when that hook gets called, and the rmdir()
function I was using to delete the directory fails because the directory isn't empty.
So: Is there a hook I can call that will run after the files have been deleted? I suppose I could write my own code in hook_node_delete()
to delete the files and then the directory, but I'd rather not hack around the architecture like that, if possible.
This hook is invoked from node_delete_multiple() after the type-specific hook_delete() has been invoked, but before hook_entity_delete and field_attach_delete() are called, and before the node is removed from the node table in the database.
so have you tried doing this in api.drupal.org/api/drupal/modules%21field%21field.attach.inc/… ?