在Windows和Linux目录名称中禁止什么字符? [英] What characters are forbidden in Windows and Linux directory names?

查看:160
本文介绍了在Windows和Linux目录名称中禁止什么字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这在Linux中是非法的,在Windows
(我认为) * 中,以下是非法的。 code> / \ [ ] ; | =



我还缺少什么?



然而,我需要一个全面的指南,并考虑到
双字节字符,链接到外部资源对我来说很好。



我需要先使用可能
包含禁止的名称在文件系统上创建一个目录字符,所以我打算用
下划线替换这些字符,然后我需要将这个目录及其内容写入一个zip文件
(使用Java),所以关于zip目录名称的其他建议
将不胜感激。

解决方案

禁止文件名字符的综合指南在Windows b上不起作用因为它保留文件名和字符。是的,像
* 而其他的则是禁止的,但是由无效的字符组成的名字是无限数量的,例如,空格和圆点是有效的文件名字符,但只能由这些字符组成的名称被禁止。



Windows不区分大写字母和小写字符,因此如果命名为$ $ c $,则无法创建名为 A 的文件夹c> a 已经存在,更糟糕的是,似乎允许的名称,如 PRN CON Windows还有几个长度限制;如果移动到另一个文件夹,则在一个文件夹中有效的文件名可能无效。
命名文件和文件夹
在MSDN上。



你一般来说,不能使用用户生成的文本来创建Windows目录名称要允许用户命名任何他们想要的东西,你必须创建一个安全的名字,如 A AB A2 等,将用户生成的名称及其路径等价物存储在应用程序数据文件中,并在应用程序中执行路径映射。



如果您绝对必须允许用户生成的文件夹名称,唯一的方法来判断它们是否无效是捕获异常并假定该名称无效。即使这是充满危险的,因为拒绝访问的异常,离线驱动器和驱动器空间与可以抛出无效名称的异常重叠。你正在打开一个巨大的伤害。


I know that / is illegal in Linux, and the following are illegal in Windows (I think) * . " / \ [ ] : ; | = ,

What else am I missing?

I need a comprehensive guide, however, and one that takes into account double-byte characters. Linking to outside resources is fine with me.

I need to first create a directory on the filesystem using a name that may contain forbidden characters, so I plan to replace those characters with underscores. I then need to write this directory and its contents to a zip file (using Java), so any additional advice concerning the names of zip directories would be appreciated.

解决方案

A "comprehensive guide" of forbidden filename characters is not going to work on Windows because it reserves filenames as well as characters. Yes, characters like * " ? and others are forbidden, but there are a infinite number of names composed only of valid characters that are forbidden. For example, spaces and dots are valid filename characters, but names composed only of those characters are forbidden.

Windows does not distinguish between upper-case and lower-case characters, so you cannot create a folder named A if one named a already exists. Worse, seemingly-allowed names like PRN and CON, and many others, are reserved and not allowed. Windows also has several length restrictions; a filename valid in one folder may become invalid if moved to another folder. The rules for naming files and folders is on MSDN.

You cannot, in general, use user-generated text to create Windows directory names. If you want to allow users to name anything they want, you have to create safe names like A, AB, A2 et al., store user-generated names and their path equivalents in an application data file, and perform path mapping in your application.

If you absolutely must allow user-generated folder names, the only way to tell if they are invalid is to catch exceptions and assume the name is invalid. Even that is fraught with peril, as the exceptions thrown for denied access, offline drives, and out of drive space overlap with those that can be thrown for invalid names. You are opening up one huge can of hurt.

这篇关于在Windows和Linux目录名称中禁止什么字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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