오지's blog

해당 폴더가 존재하지 않으면 폴더 생성 python 본문

개발노트/Python

해당 폴더가 존재하지 않으면 폴더 생성 python

오지구영ojjy90 2022. 3. 8. 21:35
728x90
반응형

그대로 코드로 옮긴다.

만약 생성하고자 하는 폴더가 해당 path에 없으면,

 해당 path에 폴더를 생성한다.

 

if not os.path.exists(os.path.join(os.getcwd(), "downloads"))

만약 생성하고자 하는 폴더가 해당 path에 없으면,

 

해당 path에 폴더를 생성한다.

os.makedirs(os.path.join(os.getcwd(), "downloads"))

 

def set_downloads_folder():
    downloads_folder = os.path.join(os.getcwd(), "downloads")
    if not os.path.exists(downloads_folder):
        os.makedirs(downloads_folder)
    return downloads_folder

 

References

https://www.tutorialspoint.com/How-can-I-create-a-directory-if-it-does-not-exist-using-Python

 

How can I create a directory if it does not exist using Python?

 

www.tutorialspoint.com

 

Comments