โดยใช้ os.path.exists(directory) ของโมดูล os คุณสามารถตรวจสอบว่ามีไดเรกทอรีอยู่หรือไม่
ตัวอย่าง
import os
if not os.path.exists('my_folder'):
print("Given path doesn't exist")
else:
print("Given path exists") หากคุณเรียกใช้รายการนี้และมีโฟลเดอร์อยู่แล้ว คุณจะได้รับข้อความ -
"Given path exists"