1import os
2
3os.path.exists("file.txt") # Or folder, will return true or false
1import os.path
2
3if os.path.isfile('filename.txt'):
4 print ("File exist")
5else:
6 print ("File not exist")
7
1import os.path
2
3if os.path.isfile('filename.txt'):
4 print ("File exist")
5else:
6 print ("File not exist")
1import os.path
2
3if os.path.exists('filename.txt'):
4 print ("File exist")
5else:
6 print ("File not exist")
1#using pathlib
2from pathlib import Path
3
4file_name = Path("file.txt")
5if file_name.exists():
6 print("exists")
7else:
8 print("does not exist")
1import os
2filename = "creating file with python function"#your file name
3print("Do ",filename," exists:- ",os.path.exists(filename))