12

I'd like to use Python 3.3.3 to test for the existence of a backup file.

Something like this:

if backup does not exist:
    create it
    write to backup

otherwise:
    run other procedures not related to backup file

Any suggestions?

2
  • 1
    please search before asking, this has been asked and answered. Commented Jan 24, 2014 at 16:46
  • 1
    duplicate of stackoverflow.com/questions/82831/… Commented Jan 24, 2014 at 16:46

2 Answers 2

5

Use os.path.exists or os.path.isfile:

>>> import os
>>> os.path.isfile('/path/to/file')
False
Sign up to request clarification or add additional context in comments.

1 Comment

Please insert here the usual warning of introducing race conditions etc...
2

Take a look at os.path.exists.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.