How to check if a file exists?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nick john
    New Member
    • Mar 2011
    • 4

    How to check if a file exists?

    I don't want to create the file if it dosen't exist I just want to see if it's there. Like have a variable return True if it is in fact there.
    Thanks,
    Nick
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    All you need is a path and function call from the os module.
    Code:
    import os
    path = "X:/subdir/file_name"
    os.path.isfile(path)

    Comment

    Working...