指定ファイルを選択状態でエクスプローラを開く

ページ名:指定ファイルを選択状態でエクスプローラを開く

''' <summary>
''' 指定ファイルを選択状態でエクスプローラを開く
''' </summary>
''' <remarks></remarks>
Public Class Form2

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim w_TergetDesktopFilePath As String = mf_GetTergetDesktopFilePath("Firefox.lnk")
        If w_TergetDesktopFilePath <> "" Then
            Dim w_Arguments As String = String.Format("/select,""{0}""", w_TergetDesktopFilePath)
            Try
                System.Diagnostics.Process.Start("EXPLORER.EXE", w_Arguments)
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.SystemModal)
            End Try
        End If
    End Sub

    Private Function mf_GetTergetDesktopFilePath(wp_SearchFileName As String) As String
        Dim ret As String = ""
        Dim w_DesktopList As New List(Of String)
        Dim w_Desktop As String = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
        If w_Desktop <> "" Then
            If w_DesktopList.IndexOf(w_Desktop) < 0 Then
                w_DesktopList.Add(w_Desktop)
            End If
        End If
        w_Desktop = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory)
        If w_Desktop <> "" Then
            If w_DesktopList.IndexOf(w_Desktop) < 0 Then
                w_DesktopList.Add(w_Desktop)
            End If
        End If
        Dim w_UsersPath As String = "C:\Users"
        Dim w_UsersPathList As String() = System.IO.Directory.GetDirectories(w_UsersPath, "*", IO.SearchOption.TopDirectoryOnly)
        For i As Integer = 0 To w_UsersPathList.Count - 1
            w_Desktop = String.Format("{0}\Desktop", w_UsersPathList(i))
            If System.IO.Directory.Exists(w_Desktop) Then
                If w_DesktopList.IndexOf(w_Desktop) < 0 Then
                    w_DesktopList.Add(w_Desktop)
                End If
            End If
        Next
        If w_DesktopList.Count > 0 Then
            Dim w_FileList As New List(Of String)
            For i As Integer = 0 To w_DesktopList.Count - 1
                Dim w_File As String = String.Format("{0}\{1}", w_DesktopList(i), wp_SearchFileName)
                If System.IO.File.Exists(w_File) Then
                    w_FileList.Add(w_File)
                End If
            Next
            If w_FileList.Count > 0 Then
                ret = w_FileList(0)
            End If
        End If
        Return ret
    End Function

End Class
 

シェアボタン: このページをSNSに投稿するのに便利です。

コメント

返信元返信をやめる

※ 悪質なユーザーの書き込みは制限します。

最新を表示する

NG表示方式

NGID一覧