title: Save File dialog with PowerShell/C# from cmd batch
body: <p>I am trying to get a gui based save file as dialog from within a windows batch script. I would like to have a new folder button left of the save &amp; cancel buttons. With no predefined filetype. So it would probably have to be set to all files.</p>
  
  <p>Something similar to this: <img src="https://i.stack.imgur.com/CpnYo.gif" alt="Save Dialog"></p>
  
  <p>(Ignore the buttons in the top left)</p>
  
  <p>I have found a nice soloution, from the top answer, for opening a file here:
  <a href="https://stackoverflow.com/questions/15885132/file-folder-chooser-dialog-from-a-windows-batch-script">File / folder chooser dialog from a Windows batch script</a></p>
  
  <p>It would be nice to have a similar soloution for a save as dialog. Most importantly I would like the ability to set the path &amp; filename to their own variables. For the purpose or sake of the example. We could insert "Hello World" as output.</p>
  
  <p>exempli gratia:</p>
  
  <pre><code>echo Hello World &gt; %variable.path%%variable.file%
  </code></pre>
  
  <p>The example below is a direct quote from the linked post.</p>
  
  <pre><code>:: chooser.bat
  :: launches a File... Open sort of file chooser and outputs choice to the console
  
  @echo off
  setlocal enabledelayedexpansion
  
  :: Does powershell.exe exist within %PATH%?
  for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
  set chooser=powershell "Add-Type -AssemblyName System.windows.forms|Out-Null;$f=New-    Object System.Windows.Forms.OpenFileDialog;$f.InitialDirectory='%cd%';$f.Filter='Text Files     (*.txt)|*.txt|All Files (*.*)|*.*';$f.showHelp=$true;$f.ShowDialog()|Out-Null;$f.FileName"
  ) else (
  rem :: If not, compose and link C# application to open file browser dialog
  set chooser=%temp%\chooser.exe
  &gt;"%temp%\c.cs" echo using System;using System.Windows.Forms;
  &gt;&gt;"%temp%\c.cs" echo class dummy{
  &gt;&gt;"%temp%\c.cs" echo public static void Main^(^){
  &gt;&gt;"%temp%\c.cs" echo OpenFileDialog f=new OpenFileDialog^(^);
  &gt;&gt;"%temp%\c.cs" echo f.InitialDirectory=Environment.CurrentDirectory;
  &gt;&gt;"%temp%\c.cs" echo f.Filter="Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
  &gt;&gt;"%temp%\c.cs" echo f.ShowHelp=true;
  &gt;&gt;"%temp%\c.cs" echo f.ShowDialog^(^);
  &gt;&gt;"%temp%\c.cs" echo Console.Write^(f.FileName^);}}
  for /f "delims=" %%I in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') do (
      if not exist "!chooser!" "%%I" /nologo /out:"!chooser!" "%temp%\c.cs" 2&gt;NUL
  )
  del "%temp%\c.cs"
  if not exist "!chooser!" (
      echo Error: Please install .NET 2.0 or newer, or install PowerShell.
      goto :EOF
  )
  )
  
  :: capture choice to a variable
  for /f "delims=" %%I in ('%chooser%') do set "filename=%%I"
  
  echo You chose %filename%
  
  :: Clean up the mess
  del "%temp%\chooser.exe" 2&gt;NUL
      goto :EOF
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xYcoC.png" alt="enter image description here"></p>
  
  <p>I have tried to adapt the above example to work for save as. But I don't understand it well enough to do so. Which is why I'm using batch scripts and not a higher functioning programming language in the first place.</p>
  
  <p>My understanding of the above is that it is Windows batch script that invokes either PowerShell, if it exists or if PowerShell doesn't exist .net if it exists. I will then have it use my existing code as an alternative if neither exist. Alternative just has user input the full path manually.</p>
  
  <pre><code>echo Set path to file:
  echo Path and file cannot contain any spaces. e.g. c:\folder_name\file.ext
  echo Be sure you include the filename.
  SET /P path1="&gt;"?
  cls
  echo path set to: %path1%
  pause
  cls
  goto :eof
  </code></pre>
  
  <p>I would have asked on the existing post. But that is not permissible in the site rules. So I asked separately. Any help or insight is welcome.</p>
  
  <p>Thank you for your time &amp; effort.</p>