How can I safely create a nested directory?

前端 未结 27 3294
旧时难觅i
旧时难觅i 2020-11-22 00:07

What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:

27条回答
  •  清歌不尽
    2020-11-22 00:32

    I use os.path.exists(), here is a Python 3 script that can be used to check if a directory exists, create one if it does not exist, and delete it if it does exist (if desired).

    It prompts users for input of the directory and can be easily modified.

提交回复
热议问题