路径中的非法字符(汉字) [英] Illegal characters in path (Chinese characters)

查看:46
本文介绍了路径中的非法字符(汉字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Directory.GetFiles 获取路径中的非法字符":

Getting an "Illegal characters in path" with Directory.GetFiles:

files = Directory.GetFiles(folderName & invoiceFile & "*.pdf")

给定实际值,文件名将如下所示:

Given the actual values, the filenames would be like so:

x:\folder1\請 010203.pdf
y:\foldera\folderb\請 040506.pdf
z:\xyz\abc\請 119906.pdf

因此是 * 通配符.我可以在 Directory.GetFiles 中使用汉字吗?我想我可以,因为我能够在使用 ChrW(35531) 之前在单独的 VBA 项目中使用它,所以我认为它不应该是 .NET 的问题.有人知道解决这个问题的方法吗?

Hence the * wildcard. Can I use Chinese characters with Directory.GetFiles? I think I can since I was able to use it on a separate VBA project before using ChrW(35531) so I think it shouldn't be a problem with .NET. Anyone know a fix for this?

推荐答案

您需要使用 Directory.GetFiles 方法(String, String),像这样:

You need to use Directory.GetFiles Method (String, String), like this:

files = Directory.GetFiles(folderName, invoiceFile & "*.pdf")

注意文件夹名称和过滤器是单独的参数.

Note that the folder name and the filter are separate parameters.

这篇关于路径中的非法字符(汉字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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