File / folder chooser dialog from a Windows batch script

后端 未结 9 683
一生所求
一生所求 2020-11-22 11:58

Typically, asking the user to supply a file name to a batch script is a messy affair, requiring no misspellings, quotes around paths with spaces, and so forth. Unfortunatel

9条回答
  •  醉梦人生
    2020-11-22 12:59

    Other solution with direct run PowerShell command in Batch

    rem preparation command
    set pwshcmd=powershell -noprofile -command "&{[System.Reflection.Assembly]::LoadWithPartialName('System.windows.forms') | Out-Null;$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog; $OpenFileDialog.ShowDialog()|out-null; $OpenFileDialog.FileName}"
    
    rem exec commands powershell and get result in FileName variable
    for /f "delims=" %%I in ('%pwshcmd%') do set "FileName=%%I"
    
    echo %FileName%
    

提交回复
热议问题