By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

How to check if a file exists?

P: 4
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.
Mar 27 '11 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
All you need is a path and function call from the os module.
Expand|Select|Wrap|Line Numbers
  1. import os
  2. path = "X:/subdir/file_name"
  3. os.path.isfile(path)
Mar 27 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.