New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pathlib glob case sensitivity issue on Windows #70842
Comments
On Windows Path.glob does not always return the file name with correct case. If the current directory contains a file named MixedCase.txt then the following script: import pathlib
p = pathlib.Path('.')
print(list(p.glob('*.txt')))
print(list(p.glob('Mixedcase.txt'))) yields: Problem: The result of the second call to glob should be 'MixedCase.txt' as well. I would expect that glob returns a file name exactly as it is spelled in the file system. |
The problem is that there is no way to just read a file name exactly as it is spelled in the file system. Iterating all names in the directory and finding the one that match specified name ignoring case is not such effective as checking that specified file name exists. |
So this is a trade-off between consistent behavior and efficiency. My point of view is that glob is for enumerating matching files and it should consistently return the real file names. Typically glob will be called with a pattern like '*.txt' and it will have to iterate names anyway, right? In the special case that it is called with a literal name it could do the same to produce consistent results. A user who wants to check (more efficiently) if a literal name exists, can use Path.exists(). The statement in the doc could be: |
For now glob(r'c:\very\long\case\insensitive\path\*.txt') have to iterate names only in one directory. For restoring actual path case it have to iterate all parent directories: r'c:\very\long\case\insensitive\path', r'c:\very\long\case\insensitive', r'c:\very\long\case', r'c:\very\long', r'c:\very', and 'c:\\'. |
Meanwhile I realized this problem as well. There is no easy solution to determine exact spelling of the entire path. So it seems there is no simple solution to my problem. The concept of treating file system paths case-insensitive (as Windows does) seems to be a bad idea. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: