implementation of create_path_and_dirs funcions.