简体   繁体   English

如何在 Windows 上使用不属于 UTF-8 的字符创建文件名?

[英]How to create filename with characters that are not part of UTF-8 on Windows?

[Edit/Disclaimer]: Comments pointed out that I have to clarify the encoding the user uses. [编辑/免责声明]:评论指出我必须澄清用户使用的编码。 Will update accordingly会相应更新

I have a customer from China who recently reported an issue with their filenames on Windows.我有一位来自中国的客户最近报告了他们在 Windows 上的文件名问题。 The software works with most Chinese characters, but it seems he has found one file that fails.该软件适用于大多数汉字,但他似乎发现了一个失败的文件。

Unfortunately, they are not able to send me over the filename as neither zipping nor transmitting the file through other mediums seem to preserve the filename.不幸的是,他们无法通过文件名向我发送文件,因为压缩文件或通过其他媒体传输文件似乎都不会保留文件名。

What is the easiest way (eg through Python) to generate a filename on Windows that is covered by the NTFS file system encoding but not UTF8 ?在 Windows 上生成由 NTFS 文件系统编码而不是UTF8覆盖的文件名的最简单方法是什么(例如通过 Python)?

Unicode strings are encoded as a series of bytes. Unicode 字符串被编码为一系列字节。 The rules of what a series of bytes visually looks like to you in an operating system, is what operating systems use to turn bytes into characters.操作系统中一系列字节在视觉上看起来是什么样子的规则,就是操作系统用来将字节转换为字符的规则。

Given that Windows uses a (variation of-) Unicode, and you say you have a character that's not in unicode, it also means that there is simply no way to represent that character.鉴于 Windows 使用(-的变体)Unicode,并且您说您有一个不是 unicode 的字符,这也意味着根本无法表示该字符。

Imagine if unicode only contained the numbers 0-9, and you ask someone how to encode the letter A .想象一下,如果 unicode 只包含数字 0-9,并且您问某人如何对字母A进行编码。 There's no answer to this, because only 0-9 are defined.对此没有答案,因为只定义了 0-9。

You could make up a new unicode codepoint for your character, but then operating systems won't know what to do with that unless you also make your own font files.你可以为你的角色创建一个新的 unicode 代码点,但是操作系统不会知道如何处理它,除非你也制作自己的字体文件。

I somehow doubt that that's what you want to do though, but it's an option.我以某种方式怀疑这就是您想要做的,但这是一种选择。 Could your customer rename the file before sending it to you?您的客户能否在将文件发送给您之前重命名该文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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