Return to Snippet

Revision: 36870
at December 7, 2010 13:46 by eliluminado


Updated Code
file = "/usr/bin/firefox"

def CheckFile(file):
    import os.path
    if os.path.exists(file):
        print "The file exists"
    else:
        print "The file does not exist"


def CheckFile2(file):
    import os.path
    if os.path.isfile(file):
        print "The file exists"
    else:
        print "The file does not exist"


def CheckFile3(file):
    try:
        archive = open(file)
        print "The file exists"
    except IOError:
        print "The file does not exist"

Revision: 36869
at November 29, 2010 06:25 by eliluminado


Initial Code
file = "/usr/bin/firefox"

def CheckFile(file):
    import os.path
    if os.path.exists(file):
        print "The file exists"
    else:
        print "The file does not exist"

def CheckFile2(file):
    import os.path
    os.path.isfile(file)


def CheckFile3(file):
    try:
        archive = open(file)
        print "The file exists"
    except IOError:
        print "The file does not exist"

Initial URL
http://www.codigopython.com.ar/miniguias/tres-formas-de-comprobar-la-existencia-de-un-archivo

Initial Description
Tres formas de comprobar la existencia de un archivo:
Three ways to test the existence of a file:

Initial Title
Three ways to test the existence of a file

Initial Tags
file

Initial Language
Python