0

I found a powershell script to open up a gui filepicker now how do I get the file I pick in it to be plugged into a variable? Also I have a program called binsmp that replaces hex in files from the command line how would I plug the file into that?

@echo off
setlocal
for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do (
echo You chose %%~I
)
goto :EOF

Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd
$f.Filter = "Roms (*.sfc;*.smc)|*.sfc;*.smc|All Files (*.*)|*.*"
$f.ShowHelp = $false
$f.Multiselect = $false
[void]$f.ShowDialog()
if ($f.Multiselect) { $f.FileNames } else { $f.FileName }

binsmp filename -paste paste.txt
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • Your pretty close there, but you need to modify the powershell script part to replace `binsmp filename` with something like `binspmp $f.FileName`. My Powershell foo is a bit weak, but I suspect you can remove the `if ($f.Multiselect...` line. – jwdonahue Jan 11 '18 at 03:58
  • This script that I got puts a output out how would I remove the output so it only opens the gui up? – NilvaVunner Jan 11 '18 at 04:16
  • Where did you get this script? It seems to be broken. – jwdonahue Jan 11 '18 at 04:22
  • See https://stackoverflow.com/questions/2609985/how-to-run-a-powershell-script-within-a-windows-batch-file. – jwdonahue Jan 11 '18 at 04:30
  • https://stackoverflow.com/a/15885133/1683264 – NilvaVunner Jan 11 '18 at 04:31

1 Answers1

0

Assuming that the filename part of your binsmp invocation is where the actual filename is supposed to be, give this a try:

<# :
:: launches a File... Open sort of file chooser and outputs choice(s) to the console
:: https://stackoverflow.com/a/15885133/1683264

@setlocal
@echo off

for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do (
    binsmp %%~I -paste paste.txt
)
goto :EOF

: end Batch portion / begin PowerShell hybrid chimera #>

Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd
$f.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
$f.ShowHelp = $true
$f.Multiselect = $true
[void]$f.ShowDialog()
if ($f.Multiselect) { $f.FileNames } else { $f.FileName }

You broke it when you removed the totally non-standard/supported powershell comment block around the actual cmd script code.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43