Answers for "file exist or not in python"

81

python check if file exists

import os

os.path.exists("file.txt") # Or folder, will return true or false
Posted by: Guest on February-14-2020
9

file exist python

import os.path

if os.path.exists('filename.txt'):
    print ("File exist")
else:
    print ("File not exist")
Posted by: Guest on May-13-2020
2

how to check if some file exists in python

import os
filename = "creating file with python function"#your file name
print("Do ",filename," exists:- ",os.path.exists(filename))
Posted by: Guest on October-05-2021
1

how to check if a file exists in python

# Python program to explain os.path.exists() method   
      
# importing os module   
import os  
    
# Specify path  
path = '/usr/local/bin/'
    
# Check whether the specified  
# path exists or not  
isExist = os.path.exists(path)  
print(isExist)  
    
    
# Specify path  
path = '/home/User/Desktop/file.txt'
    
# Check whether the specified  
# path exists or not  
isExist = os.path.exists(path)  
print(isExist)  

# credit to geeksforgeeks.com at
# https://www.geeksforgeeks.org/python-check-if-a-file-or-directory-exists/
Posted by: Guest on September-18-2020

Code answers related to "file exist or not in python"

Python Answers by Framework

Browse Popular Code Answers by Language