简体   繁体   English

文件名中的“ /”,而不是目录分隔符

[英]“/” in filename, not as a directory separator

My problem is that if the user enters a filename with a "/" in it, it will be saved to another directory. 我的问题是,如果用户输入的文件名中带有“ /”,它将被保存到另一个目录。 Is there a way to prevent this, so I could have "/" in the filename? 有没有办法防止这种情况,所以我可以在文件名中使用“ /”?

For example, the file named "page 8/9.txt"should not be saved in the directory "page 8" as "9.txt." 例如,名为“ page 8 / 9.txt”的文件不应作为“ 9.txt”保存在目录“ page 8”中。

Edit: 编辑:
The : worked fine for me! :对我来说很好! thanks Paul R 感谢Paul R

No, "most" file systems (I can't think of any counter-examples, though I assume some do exist) disallow the / character, even those that don't use it as a directory separator (eg FAT and NTFS). 不,“大多数”文件系统(尽管我认为确实存在,但我想不出任何反例)不允许使用/字符,即使那些不将其用作目录分隔符的文件系统(例如FAT和NTFS)也是如此。

You're going to have to sanitise your input, but that's a good general habit to get into anyway! 您将必须清理输入内容,但是无论如何,这是一个很好的一般习惯!

Mac OS X通常透明地将/转换为:反之亦然 ,只要您不绕过用于文件系统导航和文件I / O的常用API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM