Fixing if directory exist check

Minor addition to check. Only run if directory exists.