Three ways to test the existence of a file


/ Published in: Python
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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"

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.