Vb.net 当我只有部分名称时,如何选择文件?
我正在构建一个应用程序,可以打开不同文件夹中的各种文件。我需要打开应用程序,随后打开一个Powerpoint演示文稿,该演示文稿的名称开头有“1”。我该怎么做? 我编写了以下代码,但只有输入确切的名称,它才能工作:Vb.net 当我只有部分名称时,如何选择文件?,vb.net,process,wildcard,presentation,Vb.net,Process,Wildcard,Presentation,我正在构建一个应用程序,可以打开不同文件夹中的各种文件。我需要打开应用程序,随后打开一个Powerpoint演示文稿,该演示文稿的名称开头有“1”。我该怎么做? 我编写了以下代码,但只有输入确切的名称,它才能工作: If (System.IO.File.Exists("FilePath\1*")) Then 'Lists File Names from folder & when selected, opens selected file in default program
If (System.IO.File.Exists("FilePath\1*")) Then
'Lists File Names from folder & when selected, opens selected file in default program
Dim file3dopen As New ProcessStartInfo()
With file3dopen
.FileName = "TheFilepath\1*"
.UseShellExecute = True
End With
Process.Start(file3dopen)
Else
MsgBox("No Such File Exists")
End If
您需要使用
directory.GetFiles(字符串路径,字符串模式)
查找该目录中的所有文件
谢谢-我所要做的就是将IO添加到第一行,这就像一个魅力。谢谢。有关在Visual Studio 2010.Dim文件中作为String()=IO.Directory.GetFiles(“\FilePath”,“1*”)工作的代码,请参见下面的注释
Dim files As String() = Directory.GetFiles("\FilePath", "1*")
If files.Length > 0 Then ' file found
Dim file3dopen As New ProcessStartInfo()
With file3dopen
.FileName = files(0)
.UseShellExecute = True
End With
Process.Start(file3dopen)
Else
'file not found
MsgBox("No Such File Exists")
End If