Pages

Tuesday, October 21, 2014

Python: check if file or directory exists








  • os.path.exists to check if file or directory exists.
    import os
    os.path.exists('/tmp/1.txt')
    os.path.exists('/tmp')
    
  • os.path.isfile to check if file exists.
    import os
    os.path.isfile('/tmp/1.txt')
    



No comments:

Post a Comment