Check to See If File Exists in Python

July 11, 2008 at 9:20 pm 6 comments

import os
os.path.exists(fileName)

This returns a boolean value.

Advertisements

Entry filed under: Uncategorized.

Increase the Text Size on Axes of Plots in R How to Do an IF Statement in SQL

6 Comments Add your own

  • 1. sandrar  |  September 10, 2009 at 8:09 pm

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

  • 2. murpium  |  October 8, 2010 at 7:33 pm

    Very handy example. Thank you.

  • 3. ben  |  February 23, 2012 at 4:52 pm

    searched a lot .. find in your blog !!!

  • 4. Ephraim  |  June 10, 2014 at 11:59 pm

    How would use an if statement with it so it wouldn’t print ‘True’ or ‘False’?

  • 5. Admin  |  June 11, 2014 at 1:35 am

    if os.path.exists(filename):
    print “File exists”
    else:
    print “File does not exist”

  • 6. Shwetha  |  April 27, 2016 at 11:31 am

    what if file name is stored in 2 diff variable say ex server name is in variable called server and JVM name is in variable called JVM and the file name is $server$JVM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed



%d bloggers like this: