文件(夹)名避免使用的字符 Characters to Avoid in Directories and Filenames
2014-04-23 17:58
591 查看
Characters to Avoid in Directories and Filenames
Your web files will be viewed by numerous users who use a wide variety of operating systems (Mac, PC, and Linux for instance) and devices (desktops, tablets, and smartphones are some examples). Therefore, it is essential to play it safe and avoid common
illegal directory and filename characters.
Naming conventions are important in web folders as well as for downloadable files such as PDFS, Word documents, and Excel spreadsheets.
Do not use any of these common illegal characters/symbols:
Also, keep these rules in mind.
Don’t start or end your filename with a space, period, hyphen, or underline.
Keep your filenames to a reasonable length and be sure they are under 31 characters.
Most operating systems are case sensitive; always use lowercase.
Avoid using spaces and underscores; use a hyphen instead.
what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os
Windows: anything except ASCII's control characters and \/:*?"<>|
Linux, OS-X: anything except null or /
On all platforms it is best to avoid non-printable characters such as the ASCII control-characters.
Windows
In Windows, Windows Explorer does not allow control-characters or
filesystem such as NTFS apparently store the encoding with the filename, but UTF-16 is standard.
Linux, OS-X
In Linux and OS-X only
Linux filesystems such as ext2, ext3 are character-set agnostic (I think they just treat it more or less as a byte stream - only nulls and
or other application to know what encoding to use to properly convert the filename for display or processing.
Conclusion
So you could probably safely use something like
过滤windows文件名非法字符
windows现在已知的文件名非法字符有 \ / : * ? " < > |
Your web files will be viewed by numerous users who use a wide variety of operating systems (Mac, PC, and Linux for instance) and devices (desktops, tablets, and smartphones are some examples). Therefore, it is essential to play it safe and avoid common
illegal directory and filename characters.
Naming conventions are important in web folders as well as for downloadable files such as PDFS, Word documents, and Excel spreadsheets.
Do not use any of these common illegal characters/symbols:
# pound | < left angle bracket | $ dollar sign | + plus sign |
% percent | > right angle bracket | ! exclamation point | ` backtick |
& ampersand | * asterisk | ‘ single quotes | | pipe |
{ left bracket | ? question mark | “ double quotes | = equal sign |
} right bracket | / forward slash | : colon | |
\ back slash | blank spaces | @ at sign |
Don’t start or end your filename with a space, period, hyphen, or underline.
Keep your filenames to a reasonable length and be sure they are under 31 characters.
Most operating systems are case sensitive; always use lowercase.
Avoid using spaces and underscores; use a hyphen instead.
what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os
Windows: anything except ASCII's control characters and \/:*?"<>|
Linux, OS-X: anything except null or /
On all platforms it is best to avoid non-printable characters such as the ASCII control-characters.
Windows
In Windows, Windows Explorer does not allow control-characters or
\/:*?"<>|You can use spaces. If you use spaces, you will often have to quote the filename when used from the command line (but GUI apps are unaffected so far as I know). Windows
filesystem such as NTFS apparently store the encoding with the filename, but UTF-16 is standard.
Linux, OS-X
In Linux and OS-X only
/of the printable ASCII set is prohibited I believe. Some characters (shell metacharacters like
*?!) will cause problems in command lines and will require the filename to be appropriately quoted or escaped.
Linux filesystems such as ext2, ext3 are character-set agnostic (I think they just treat it more or less as a byte stream - only nulls and
/are prohibited). This means you can store filenames in UTF-8 encoding. I believe it is up to the shell
or other application to know what encoding to use to properly convert the filename for display or processing.
Conclusion
So you could probably safely use something like
✣(if it weren't so hard to type)
过滤windows文件名非法字符
windows现在已知的文件名非法字符有 \ / : * ? " < > |
private static Pattern FilePattern = Pattern.compile("[\\\\/:*?\"<>|]"); public static String filenameFilter(String str) { return str==null?null:FilePattern.matcher(str).replaceAll(""); }
相关文章推荐
- FW: Characters to Avoid in Directories and Filenames
- 将字符串转成单个的字符Split a string to characters in Bash{转}
- Using POI to replace elements in WORD(.docx)(使用POI替换word中的特定字符/文字)
- 本地提交SVN报错 提交文件 is not known to exist in the repository and is not part of the commit, yet its child
- Saving Workbooks to PDF and XPS Formats in Excel 2007 (C#.net word excel powerpoint (ppt) 转换成 pdf 文件)
- Java Tips and Best practices to avoid NullPointerException in Java Applications
- PHP使用copy函数复制windows文件时出现failed to open stream: Invalid argument in错误
- [转]Use PowerShell to Manage Lists, Views, and Items in SharePoint(使用PowerShell管理列表、视图、列表项)
- 使用componentsSeparatedByCharactersInSet:方法限定输入字符的格式
- Advanced Techniques To Avoid And Detect Deadlocks In .NET Apps(线程死锁和检测-译【待续】)
- How to use logrotate to manage log files in linux(如何在Linux中使用logrotate去管理日志文件)
- How to detect and avoid memory and resources leaks in .NET applications
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- 使用Mono Cecil 动态获取运行时数据 (Atribute形式 进行注入 用于写Log) [此文报考 xxx is declared in another module and needs to be imported的解决方法]-摘自网络
- How to Insert OLE Object (Adobe Acrobat Document) in Word with C#(如何使用C#在Word中插入OLE对象-PDF文件)
- Using POI to replace elements in WORD(.docx/.doc)(使用POI替换word中的特定字符/文字)【改进】
- WIN7下VC6.0无法使用打开文件功能(Unable to register this add-in because its DLLRegisterServer return an error)
- How to detect and avoid memory and resources leaks in .NET applications
- How to detect and avoid memory and resources leaks in .NET applications
- Welcome-to-Swift-03字符串和字符(Strings and Characters)