Running rmdir function on post save

Add this to your theme’s functions.php file:

function wpse202681_save_post_action($post_id, $post_object, $update) {
    $folder = "/temp/files/";
    delFolder($folder);
}
add_action( 'save_post', 'wpse202681_save_post_action', 10, 3 );
// + delFolder() function definition

You will probably have to alter folder paths depending on your /temp/files/ location.

This will execute everytime any post is saved. You can restrict it to only some post type, etc.