how to check whether file exists in python
import os.path
if os.path.isfile('filename.txt'):
print ("File exist")
else:
print ("File not exist")
how to check whether file exists in python
import os.path
if os.path.isfile('filename.txt'):
print ("File exist")
else:
print ("File not exist")
python how to see if file is directory
"""
Use os.path.isfile(some_string) to check if some_string is a file
Use os.path.isdir(some_string) to check if some_string is a directory
"""
import os
path = "C:/some directory/"
file = path + "file.txt"
print("variable path is a file:", os.path.isfile(path) )
print("variable path is a directory:", os.path.isdir(path) )
print()
print("variable file is a file:", os.path.isfile(file) )
print("variable file is a directory:", os.path.isdir(file) )
python os if file exists
import os.path
if os.path.isfile('filename.txt'):
print ("File exist")
else:
print ("File not exist")
file exist python
import os.path
if os.path.exists('filename.txt'):
print ("File exist")
else:
print ("File not exist")
python check if file exists
#using pathlib
from pathlib import Path
file_name = Path("file.txt")
if file_name.exists():
print("exists")
else:
print("does not exist")
python if certain file is in a directory
import os
os.path.exists('./final_data_2020.csv')
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us