The scenario I have in mind is as follow:
- User drags a file (example text.txt
) onto the .bat
script.
- Batch file opens the Save Dialog box, allowing the user to save this file under another name.
As I understand, I should define the file to be dragged and dropped, as %1
and what I am missing is how to open the Save Dialog box from the batch file.
My current code is:
<# : chooser.bat
:: launches a File... Open sort of file chooser and outputs choice(s) to the console
:: https://stackoverflow.com/a/15885133/1683264
@echo off
setlocal
for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do (
echo You chose %%~I
)
goto :EOF
: end Batch portion / begin PowerShell hybrid chimera #>
Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
:: i tried to change $f = new-object Windows.Forms.SaveFileDialog
$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 }