Your comments

I notice that if you delete the currently editing file, then the display goes blank (as I'd expect). So it seems the only thing that needs doing is to recurse through folders and perform the same action when any parent folder is removed as well.