I hate to be the person to post another FileNotFoundError question, but most of them that I see are about not giving the full path to the file, that is not my problem here.
I have a number of log files in folders in ../../Data/
. I create a glob of those files using
DataFiles = glob('../../Data/2021*/*.log')
I want to open each of the files in that glob, so I use
for i, file in enumerate(DataFiles):
with open(file, "r") as f:
...
etc. 99% of these open correctly and the rest of the code runs. For some reason, a few will not. I get an error like
FileNotFoundError: [Errno 2] No such file or directory: '../../Data\\20210629_081706\\20210629_081706_data.log'
The file definitely exists, that's why it was found by glob
. The full path is used. And,
from pathlib import Path
Path('../../Data\\20210629_081706\\20210629_081706_data.log')
returns
WindowsPath('../../Data/20210629_081706/20210629_081706_data.log')
So does anyone know what might be happening here?