Creating two functions from duplicated code
Removing duplications, replacing with functions
Removing duplications, replacing with functions
Removing duplications, replacing with functions
Use _file instead of file

since file is a built-in function
Return false on non existing dirs
Merge pull request #1823 from multikatt/postproc_cleanup

Create two new functions, lowering amount of duplicated code