Posted By

eliluminado on 11/29/10


Tagged

file test archive existence ways


Versions (?)

Three ways to test the existence of a file


 / Published in: Python
 

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

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

  1. file = "/usr/bin/firefox"
  2.  
  3. def CheckFile(file):
  4. import os.path
  5. if os.path.exists(file):
  6. print "The file exists"
  7. else:
  8. print "The file does not exist"
  9.  
  10.  
  11. def CheckFile2(file):
  12. import os.path
  13. if os.path.isfile(file):
  14. print "The file exists"
  15. else:
  16. print "The file does not exist"
  17.  
  18.  
  19. def CheckFile3(file):
  20. try:
  21. archive = open(file)
  22. print "The file exists"
  23. except IOError:
  24. print "The file does not exist"

Report this snippet  

You need to login to post a comment.