vb.net - 具有未知文件扩展名(但已知名称)的文件的 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 )但我不太了解如何使用它。尝试像这样使用时出现错误 Regex cannot be converted to string :
// 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)
解决方案
推荐阅读
- python - 如何有效地读取巨大 tiff 图像的一部分?
- javascript - react native 中的全局 onChange 处理程序
- matlab - 用加号填充行之间
- javascript - React-Router 在浏览器中显示组件两次
- android - 如何在 Android 中使用 Regex、SpannableString 更改特定文本的颜色
- python - 如何在 Python 中转换指数并去掉“e+”?
- c - 可编程中断控制器:PIC1 和 PIC2 在实模式下不返回零
- javascript - 在firebase中分页时如何检测第一页或最后一页中的am
- python - argparse:在一个破折号中有多个标志的 nargs?
- linux - 执行和获取 bash 文件的所有选项有哪些?为什么不检查shebang?