在实际创建文件之前,查找文件名是否有效 [英] Find if a file name is valid before actually creating the file

查看:108
本文介绍了在实际创建文件之前,查找文件名是否有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 一种方法是检查文件是否已在系统上创建并告诉用户它是一个无效的字符串。

  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).

另一种方法是解析整个字符串以检查其是否具有无效的文件名字符,例如< /, \\ etc中的字符串。

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?

推荐答案

您可以使用静态函数:

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.

这篇关于在实际创建文件之前,查找文件名是否有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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