-1

I am building an application that opens all kinds of files from different folders. I need to open the application by subsequently opening a Powerpoint presentation which has "1" at the beginning of its name. How should I do this? I wrote the following code but it works only if I put in the exact name:

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
Simon
  • 31,675
  • 9
  • 80
  • 92
Wise Indian
  • 91
  • 4
  • 13

1 Answers1

1

You need to look for all the files in that directory using 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
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
  • Thanks - all I had to do to make it work for VS 2010 is add IO to the first line and it worked like a charm. Thanks a lot. See the below comment for the code that works in Visual Studio 2010. – Wise Indian Mar 12 '13 at 00:50
  • Dim files as String() = IO.Directory.GetFiles("\FilePath", "1*") – Wise Indian Mar 12 '13 at 00:50