windows Windows文件名中的分号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3869594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:22:22  来源:igfitidea点击:

semi colons in Windows filenames?

windowsgetopenfilename

提问by Jeff

One of my users asked why my app does not support semi-colons in filenames. I stepped through my code, seems Windows function GetOpenFileName truncates any filename containing a semi-colon. e.g. "one;two.wav" -> "one".

我的一位用户问为什么我的应用程序不支持文件名中的分号。我逐步完成了我的代码,似乎 Windows 函数 GetOpenFileName 会截断任何包含分号的文件名。例如“一;二.wav”->“一”。

Microsoft says colons are not allowed, but don't mention semi-colons...

微软说不允许使用冒号,但不要提到分号......

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx

Are they legal or not?

它们是否合法?

EDIT: ..and how to GetOpenFileName() to work with semi-colons in filename?

编辑: .. 以及如何 GetOpenFileName() 使用文件名中的分号?

OH!, Weird - Filename is correct, except 'scrolled' off to the left. So "one;two.wav" looks like "two.wav" until I click it and press left-arrow (then it's fine). So it's not a bug as such, only weird behaviour.

哦!,奇怪 - 文件名是正确的,除了“向左滚动”。所以“one;two.wav”看起来像“two.wav”,直到我点击它并按左箭头(然后就可以了)。所以这不是一个错误,只是奇怪的行为。

回答by Michael Petrotta

Semicolons are legal in NTFS file paths.

分号在 NTFS 文件路径中是合法的

Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

The following reserved characters:

  • < (less than)
  • (greater than)

  • : (colon)
  • " (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • (asterisk)
  • Integer value zero, sometimes referred to as the ASCII NUL character.
  • Characters whose integer representations are in the range from 1 through 31, except for alternate streams where these characters are allowed.
  • Any other character that the target file system does not allow.

使用当前代码页中的任何字符作为名称,包括 Unicode 字符和扩展字符集 (128–255) 中的字符,但以下字符除外:

以下保留字符:

  • <(小于)
  • (比...更棒)

  • : (冒号)
  • "(双引号)
  • /(正斜杠)
  • \(反斜杠)
  • | (垂直条或管)
  • ? (问号)
  • (星号)
  • 整数值零,有时称为 ASCII NUL 字符。
  • 整数表示在 1 到 31 范围内的字符,但允许这些字符的备用流除外。
  • 目标文件系统不允许的任何其他字符。

I'm able to add semicolons to filenames on my Win7 system. Watch for code, probably yours or third-party code, that does strange things with unexpected characters (most notably spaces).

我可以在我的 Win7 系统上为文件名添加分号。注意代码,可能是您的代码或第三方代码,它使用意外字符(最显着的是空格)执行奇怪的操作。

回答by Vertilizer

Though it may be omitted in the Windows handbooks, the semicolon is a reserved character too, for example "dir .dat;.bak" is a legal command. The same applies to the plus character, for example "copy test1.dat+test2.dat test3.dat" is a legal command.

尽管在 Windows 手册中它可能被省略,但分号也是一个保留字符,例如“dir .dat;.bak”是一个合法的命令。这同样适用于加号,例如“copy test1.dat+test2.dat test3.dat”是一个合法的命令。

回答by Henk

True: Windows allows a semicolon in file names. But when you burn such files to a data CD or DVD disc, the names get truncated. This I experienced when using aHead Nero version 9.

正确:Windows 允许在文件名中使用分号。但是,当您将此类文件刻录到数据 CD 或 DVD 光盘时,名称会被截断。这是我在使用 aHead Nero 版本 9 时遇到的。

回答by drhanlau

Yes, they are allowed. Just that if you are running them in the command line you have to put quotes within them.

是的,他们被允许。只是,如果您在命令行中运行它们,则必须在其中加上引号。

回答by Andrew Cooper

Yes. A semi-colon is a legal character in a Windows file-name. It wouldn't surprise me, though, if there were other programs that had a problem with them.

是的。分号是 Windows 文件名中的合法字符。不过,如果其他程序有问题,我也不会感到惊讶。