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

Viewed 707

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:\Users\jerfo\AppData\Local\xmr-haystack\xmr-haystack\Cache. 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:\Users\jerfo\AppData\Local\, but I could not find the xmr-haystack directory. I confirmed this by attempting to run the command cd C:\Users\jerfo\AppData\Local\xmr-haystack\xmr-haystack\Cache, 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:\\Users\\jerfo\\AppData\\Local\\xmr-haystack\\xmr-haystack\\Cache'
file_path = os.path.join(cache_dir, 'cache.json')

os.makedirs(cache_dir, exist_ok=True) # No errors
f = open(file_path, 'w') # No errors
f.write('hello') # No errors
f.close() # Still no errors

print(os.path.exists(cache_dir)) # Prints True, yet the folder doesn't exist
print(os.path.exists(file_path)) # Prints True, yet the file doesn't exist

Link to video showing code in action

Link to screenshot of the same code demo in video, if unavailable.

0 Answers
Related