For some reason os.path.isfile() occasionally returns false for some existing Windows files. At first, I assumed that spaces in the filename were causing a problem, but other file paths with spaces worked fine. Here's copy from the Python console that illustrates this issue:
>>> import os
>>> os.path.isfile("C:\Program Files\Internet Explorer\images\bing.ico")
False
>>> os.path.isfile("C:\Program Files\Internet Explorer\images\PinnedSiteLogo.contrast-black_scale-80.png")
True
How can I fix this problem?
\b
in a string means backspace. If you want actual backslashes in a string, they need to be escaped with more backslashes (\\
instead of \
), or you need to use a raw string (r"..."
instead of "..."
). For file paths, I'd recommend using forward slashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With