1import os
2
3os.path.exists("file.txt") # Or folder, will return true or false
1import os
2print(os.path.isdir("/home/el"))
3print(os.path.exists("/home/el/myfile.txt"))
1import os.path
2
3if os.path.isfile('filename.txt'):
4 print ("File exist")
5else:
6 print ("File not exist")
7
1import os.path
2from os import path
3
4def main():
5
6 print ("File exists:"+str(path.exists('guru99.txt')))
7 print ("File exists:" + str(path.exists('career.guru99.txt')))
8 print ("directory exists:" + str(path.exists('myDirectory')))
9
10if __name__== "__main__":
11 main()
1import os
2os.path.isdir("/home/el") # Returns True if exist
3os.path.exists("/home/el/myfile.txt") # Return False if not exist