简体   繁体   中英

How to create case-sensitive file in python on windows?

I want to create both A.txt and a.txt

f = codecs.open('A.txt', 'w', 'utf-8')
f = codecs.open('a.txt', 'w', 'utf-8')

But turned out it just created A.txt on windows.

Can it be forced to create case-sensitive file? If not on *nix.

Filenames on the NTFS file system (the default for Windows) are not case sensitive. From a quick search it seems that, if case sensitive filenames are important to you, you should just use a *nix OS. It's a significant effort to make Windows work with case sensitive filenames.

Quoting from http://support.microsoft.com/kb/100625

As part of the requirements for POSIX compliance, the Windows NT File System (NTFS) provides a case-sensitive file and directory naming convention. Even though NTFS and the POSIX subsystem each handle case-sensitivity well, 16-bit Windows-based, MS-DOS-based, OS/2-based, and Win32-based applications do not.

In NTFS, you can create unique file names, stored in the same directory, that differ only in case. For example, the following filenames can coexist in one directory on an NTFS volume: CASE.TXT case.txt case.TXT However, if you attempt to open one of these files in a Win32 application, such as Notepad, you would only have access to one of the files, regardless of the case of the filename you type in the Open File dialog box.

Even though it supports Case sensitive file names, if you use Win32 applications, you wont be able to enjoy that.

NTFS is case-insensitive. A.txt and a.txt are the same filename.

$ touch case.txt
$ touch CASE.txt
$ ls *.txt
case.txt  CASE.txt

you can make this work in *nix machine but in windows I'm not sure that you can make this work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM