Mearged with code from  Vishal Rajpal to allow for creation of directories that don't exsit