简体   繁体   中英

“/” 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."

Edit:
The : worked fine for me! thanks 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).

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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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