Windows上文件名中的无效字符? [英] Invalid characters in a filename on Windows?

查看:403
本文介绍了Windows上文件名中的无效字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据MSDN,以下字符不能成为文件名的一部分:

As per the MSDN , the following characters cannot be part of the file name:

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

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:

◦下列保留字符:

  • <(小于)
  • >(大于)
  • :(冒号)
  • "(双引号)
  • /(正斜杠)
  • \(反斜杠)
  • |(垂直条或管道)
  • ?(问号)
  • *(星号)
  • < (less than)
  • > (greater than)
  • : (colon)
  • " (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)

.net中提供了一个api来查找文件名中不允许的字符

In .net an api is provided to find the what are the characters not allowed in a filename

char[] invalidFileChars = Path.GetInvalidFileNameChars();

备注

不能保证从此方法返回的数组包含文件和目录名称中无效的完整字符集.无效字符的完整集合可能因文件系统而异.例如,在基于Windows的桌面平台上,无效的路径字符可能包括ASCII/Unicode字符1到31,以及引号(),小于(<),大于(>),竖线(|),退格键(\ b),空(\ 0)和制表符(\ t).

Remarks

The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. The full set of invalid characters can vary by file system. For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0) and tab (\t).

但是在备注部分中,据说这取决于文件系统.

But in the remark section it is said that it is depend on the file system.

将此API用于基于Windows的操作系统(例如XP和Windows 7)是否安全?

Is it safe to use this api for the windows based os like XP and windows 7?

推荐答案

是的,在基于ASCII的文件系统中,Path.GetInvalidFileNameChars()将保证您的文件名安全.如果您查看此处的ASCII图表,您会发现左侧列中的所有内容均被排除,其余列中的某些字符也排除在外.检查返回数组中每个 char 的十进制表示形式,以获取排除项的完整列表.

Yes, in an ASCII based file system Path.GetInvalidFileNameChars() will guarantee you a safe file name. If you check the ASCII chart here you will find that everything from the left column is excluded and certain characters from the remaining columns are also excluded. Check the decimal representation of each char in the returned array for a full list of what's excluded.

这篇关于Windows上文件名中的无效字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆