VB6 如何处理文件名含有无效字符
我用 VB6 创建了一个应用程序。我必须阅读客户邮件的附件。但附加文件的名称包含无效字符。我想复制它,但我的应用程序无法做到这一点。
如何检查文件名是否包含无效字符?
I have created an application in VB6. I have to read attachments of a mail of client. But attached file has a name with invalid characters. I want to make the copy of it but my application cannot do it.
How can I check that the file name contains invalid character?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最明显的事情是简单地用占位符替换无效字符,因此(例如)将“:”替换为“_”。 (如果我没有抓住要点,请原谅。)
OT:自 2008 年 4 月起,VB6 环境(编译器等)就不再受支持,我强烈建议使用更新的东西。 (VB6 运行时仍受支持,并且将在 Windows 7 的生命周期中,但即便如此...)
编辑:响应您的编辑:
Windows 文件名中的无效字符(因为这本质上是 Windows 应用程序)是详细记录。
The most obvious thing is to simply replace invalid characters with placeholders, so (for instance) replace ":" with "_". (Apologies if I'm missing the point.)
OT: The VB6 environment (compiler, et. al.) has been unsupported since April 2008, I'd strongly recommend using something more up-to-date. (The VB6 runtime is still supported, and will be through the lifetime of Windows 7, but even so...)
Edit: Responding to your edit:
The invalid characters in Windows filenames (since this is by its nature a Windows application) are well-documented.
如果没有更多关于如何“阅读附件”的详细信息,则很难提供具体的帮助。
您可能会遇到 Unicode BOM 前缀,可能存在来自不允许的文件名子集的字符,或者您可能正在处理控制字符或更可能具有 AscW() 值 > 的字符。 127如外国字母符号等。
您可以通过 API 调用创建具有“Unicode 文件名”的文件,但将此类符号转换为某种“splat”(如 # 或 _)可能会更简单,这样应该可以正常工作。如有必要,您可以使用 AscW(char) 和 Select Case 语句逐个字符地迭代文件名字符串,以识别“坏”字符并替换它们。
Without more detail about how you "read attachments" specific help is difficult to offer.
You might be encountering a Unicode BOM prefix, perhaps there are characters from the disallowed subset for file names, or you may be dealing with control characters or more likely characters with AscW() values > 127 such as foreign alphabet symbols and such.
You can create files with "Unicode file names" via API calls, but it may be simpler to translate such symbols to some sort of "splat" like # or _ which should work without incident. If necessary you could just iterate over the file name string character by character using AscW(char) and a Select Case statement to identify "bad" characters and replace them.