Python Verifique se o arquivo existe
import os
os.path.exists("file.txt") # Or folder, will return true or false
Duco Defiant Dogfish
import os
os.path.exists("file.txt") # Or folder, will return true or false
import os
print(os.path.isdir("/home/el"))
print(os.path.exists("/home/el/myfile.txt"))
import os.path
if os.path.isfile('filename.txt'):
print ("File exist")
else:
print ("File not exist")
>>> import os
>>> os.path.isdir('new_folder')
True
>>> os.path.exists(os.path.join(os.getcwd(), 'new_folder', 'file.txt'))
False
os.path.isdir("/home/el")
import os
os.path.isdir("/home/el") # Returns True if exist
os.path.exists("/home/el/myfile.txt") # Return False if not exist