2013-03-11 2 views
-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 

답변

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 
+0

감사합니다. VS 2010에서 작동하게하려면 감사합니다. 첫 번째 줄에는 IO를 추가해야하며 매력적이었습니다. 고마워. Visual Studio 2010에서 작동하는 코드에 대한 아래 주석을 참조하십시오. –

+0

Dim 파일을 String() = IO.Directory.GetFiles ("\ FilePath", "1 *") –

관련 문제