Bir dosyanın var olup olmadığını try
deyimini kullanmadan nasıl görebilirim?
Sizde os.path.exists
işlevi var:
import os.path
os.path.exists(file_path)
Bu, hem dosyalar hem de dizinler için True
döndürür, ancak bunun yerine
os.path.isfile(file_path)
özellikle bir dosya olup olmadığını test etmek için. Sembolik bağlantıları takip eder.
import os
os.path.exists(path) # Returns whether the path (directory or file) exists or not
os.path.isfile(path) # Returns whether the file exists or not