Added the function to make automatically directory which is needed to open an output file.