Search This Blog

Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

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')

Python: Get file absolute path

Use os.path.abspath function:
import os
os.path.abspath('abc/abc.txt')