在实际创建文件之前查找文件名是否有效

发布于 01-03 02:16 字数 324 浏览 1 评论 0原文

我有一个使用 C++ 构建的 wxWidget 应用程序。该应用程序的功能之一是它提示用户在消息框中输入字符串,然后一旦用户按下 Enter 键,它就会创建一个文件,该文件的名称就是用户输入的字符串数组。

现在我有一个问题,我想检查用户输入的字符串是否可以是有效的名称**。

  1. 一种方法是检查该文件是否已在系统上创建,并告诉用户这是一个无效字符串。(我不想这样做)。

  2. 另一种方法是解析整个字符串以检查字符串中是否包含无效的文件名字符,例如 <、/、\ 等。

有没有其他方法可以检查这个不涉及任何文件操作?

I have an wxWidget application built using C++. One of the functionalities of the application is that it prompts the user to enter a string in a message box and then once users presses Enter, it creates a file with the name of the file being the string array user entered.

Now I have an issue, I want to check if the string entered by the user can be a valid name or not**.

  1. one way is to check if the file has been created on the system and tell the user it is an invalid string.(I dont want to do this).

  2. another would be to parse the entire string to check if it has invalid file name characters like <, /, \ etc in the string.

Is there any other way I can check this which doesn't involve any file operations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌︼了一个春2025-01-10 02:16:26

您可以使用静态函数:

static wxString wxFileName::GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE)

获取与您的字符串匹配的无效字符列表。您可以在此处查看其文档。虽然它不会排除所有无效的文件名,但它可能足以满足您的需求。

You could use the static function:

static wxString wxFileName::GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE)

to get a list of invalid characters to match against your string. You can see its documentation here. Although it wont rule out all invalid filenames, it might be good enough for what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文