Quantcast
Channel: How do I check whether a file exists without exceptions? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by Sheetal Shahare for How do I check whether a file exists without exceptions?

$
0
0

Use the following code:

def findfile(filepath):  flag = False  for filename in os.listdir(filepath)    if filename == "your file name":      flag = True      break    else:      print("no file found")  if flag == True:    return True  else:    return False

Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>