I’m trying to write a Python script that needs to check if a certain file exists before doing some other operations on it. I’ve tried using the os.path.exists()
function, but it throws an exception if the file doesn’t exist. Is there a way to check if a file exists without using exceptions? Here’s the code I’ve been using:
This code works fine when the file exists, but it throws a FileNotFoundError
exception when the file doesn’t exist. Is there a way to modify this code to check for the file’s existence without throwing an exception? Or is there a better way to do this altogether?
Any help would be greatly appreciated. Thank you!