automatically detect directory