VB.NET具有未知文件扩展名(但名称已知)的文件的路径

时间:2019-03-16 17:43:38

标签: vb.net

当我知道文件名(它是常数并且不会改变)但不知道文件扩展名(可以根据Excel中的用户选择而改变)时,有人可以帮助我获取文件路径吗?

Dim MyAppPath As String = My.Application.Info.DirectoryPath
Dim ExcelfilePath As String = IO.Path.Combine(MyAppPath, "bundle\" & "Rozpis.xlsm")
Dim ExcelfileBackupPath As String = IO.Path.Combine(MyAppPath, "bundle\backup\" & "Rozpis.xlsm")

我希望它像这样-匹配任何具有特定名称“ Rozpis”的文件:

Dim MyAppPath As String = My.Application.Info.DirectoryPath
    Dim ExcelfilePath As String = IO.Path.Combine(MyAppPath, "bundle\" & "Rozpis.*")
    Dim ExcelfileBackupPath As String = IO.Path.Combine(MyAppPath, "bundle\backup\" & "Rozpis.*")

(此代码是我的应用程序简单的“自我保护”机制的一部分。)

我尝试过的事情:

我查看了正则表达式(但如果有比正则表达式更简单的方法,则更好-尝试过filemame。*-不起作用)作为可能的选择(具体来说是:(())+(doc | docx | pdf)$ / i),但我不知道如何使用它。 我遇到错误,正则表达式正则表达式无法转换为字符串

// Don´t remember the code exactly - something like this:    
// regex = New Regex as regex
Dim ExcelfilePath As String = IO.Path.Combine(MyAppPath, "bundle\" & "Rozpis." & regex)
Dim ExcelfileBackupPath As String = IO.Path.Combine(MyAppPath, "bundle\backup\" & "Rozpis" & regex)

0 个答案:

没有答案