-1

我正在构建一个从不同文件夹打开各种文件的应用程序。我需要通过随后打开名称开头有“1”的 Powerpoint 演示文稿来打开应用程序。我该怎么做?我编写了以下代码,但只有在输入确切名称时才有效:

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
4

1 回答 1

1

您需要使用 查找该目录中的所有文件Directory.GetFiles(string path, string pattern)

    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
于 2013-03-11T03:22:55.893 回答