in reply to Removing youngest directory
This is an unrelated issue but the name dirname() is completely wrong for something that modifies things. Your function names should tell you what they do. This should have been called remove_newest_directory() or something.