Use file instead of shell command to create/remove directories

Thanks @swissmanu