Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

python check is directory

  1. User

    python check is directory

  2. Assistant

    In Python, you can check if a path is a directory using the os.path.isdir() function. Here's an example:

    import os
    
    path = '/path/to/dir'
    
    if os.path.isdir(path):
        print(f'{path} is a directory')
    else:
        print(f'{path} is not a directory')
    

    In this example, os.path.isdir(path) returns True if the path exists and refers to a directory. If it doesn't exist or it refers to a file, it returns False.