博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件(夹)名避免使用的字符 Characters to Avoid in Directories and Filenames
阅读量:4050 次
发布时间:2019-05-25

本文共 2579 字,大约阅读时间需要 8 分钟。

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  

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.

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现在已知的文件名非法字符有 \ / : * ? " < > |

private static Pattern FilePattern = Pattern.compile("[\\\\/:*?\"<>|]");	public static String filenameFilter(String str) {		return str==null?null:FilePattern.matcher(str).replaceAll("");	}

转载地址:http://emici.baihongyu.com/

你可能感兴趣的文章
Idea下安装Lombok插件
查看>>
zookeeper
查看>>
Idea导入的工程看不到src等代码
查看>>
技术栈
查看>>
Jenkins中shell-script执行报错sh: line 2: npm: command not found
查看>>
8.X版本的node打包时,gulp命令报错 require.extensions.hasownproperty
查看>>
Jenkins 启动命令
查看>>
Maven项目版本继承 – 我必须指定父版本?
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>
微信小程序开发全线记录
查看>>
CCF 分蛋糕
查看>>
解决python2.7中UnicodeEncodeError
查看>>
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
机器学习实战之决策树(一)
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>