Is it possible Python can distinguish capital letter and small letter in the path of Windows?

eryk sun eryksun at gmail.com
Wed Oct 12 00:14:27 EDT 2016


On Wed, Oct 12, 2016 at 2:36 AM,  <jfong at ms4.hinet.net> wrote:
>
> I had try to find the document of the _winapi module, but can't find any in my
> installed Python directory. Can you give me a link to look for?

_winapi is not documented. It contains light wrappers around a small
set of Windows functions. It's ok for quick scripts if it has what you
need. But for everything else you should prefer the publicly
documented PyWin32 package, ctypes, or CFFI.

>> This alone doesn't make the Windows API case sensitive, but it does
>> enable individual CreateFile calls to be case sensitive, via the POSIX
>> semantics flag.
>
> Does it means that an application program which uses the POSIX semantics flag in its
> API call will perform case-sensitive automatically after the "obcaseinsensitive" flag was
> modified by the user?

FILE_FLAG_POSIX_SEMANTICS has to be specified in every CreateFile call.

The real system call is NtCreateFile. Like all other named objects in
the NT kernel, a file path is passed to NtCreateFile in a
OBJECT_ATTRIBUTES structure, which can be flagged as
OBJ_CASE_INSENSITIVE. When WinAPI CreateFile calls NtCreateFile, it
almost always uses the OBJ_CASE_INSENSITIVE flag. The exception is
when the caller requests FILE_FLAG_POSIX_SEMANTICS.

However, the latter is no longer enough in Windows XP and later (NT
5.1+), for which the default was switched to case insensitive for all
object manager and I/O manager objects such as devices and files. To
get the old behavior back, and thus fix the now broken
FILE_FLAG_POSIX_SEMANTICS flag, you have to disable the
ObCaseInsensitive setting, as I showed.

This modification is best for administrative and short-term use, or
for systems running an NFS server. As a long-term setting it may be
problematic. Notably SQL Server and the Windows 10 Subsystem for Linux
(WSL) don't work properly if ObCaseInsensitive is disabled.



More information about the Python-list mailing list