os.path.exists returns True even though file doesn’t exist on Windows 10

  file, io, python, python-3.x, windows

I have a strange problem with files in Windows 10. I wrote a Python program that writes some data to some cache files located in C:UsersjerfoAppDataLocalxmr-haystackxmr-haystackCache. I was able to call os.makedirs on the path and write to files within the directory without raising any errors. os.path.exists returns True for this path. However, when I tried to look at the files in File Explorer, they were not there. I navigated to C:UsersjerfoAppDataLocal, but I could not find the xmr-haystack directory. I confirmed this by attempting to run the command cd C:UsersjerfoAppDataLocalxmr-haystackxmr-haystackCache, which failed. I have reproduced this problem nearly 10 times with no noticeable changes. I have seen many people with the opposite problem (i.e. os.path.exists returns False when it shouldn’t), but I have not been able to find an instance of a problem similar to mine. Do you all have any insights into what may be causing this problem? Thank you!

Python version: 3.8.6

OS: Windows 10 Home Build 1909

Code in question:

import os

cache_dir = 'C:UsersjerfoAppDataLocalxmr-haystackxmr-haystackCache'

print(os.path.exists(cache_dir)) # Prints True! It should not

Source: Windows Questions

LEAVE A COMMENT