Check if a file exists using Python Samuel Fernandes 11-May-2015 2038 1 Answers How do I check if a file exists, using Python, without using a try statement? Last updated:5/11/2015 8:20:54 AM
Mayank Tripathi 11-May-2015 You can also use os.path.isfile Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path. import os.pathos.path.isfile(fname) You have the os.path.exists function: import os.pathos.path.exists(file_path) This returns True for both files and directories. Use os.path.isfile to test if it's a file specifically
Mayank Tripathi