.net - Save File dialog with PowerShell/C# from cmd batch -


i trying gui based save file dialog within windows batch script. have new folder button left of save & cancel buttons. no predefined filetype. have set files.

something similar this: save dialog

(ignore buttons in top left)

i have found nice soloution, top answer, opening file here: file / folder chooser dialog windows batch script

it nice have similar soloution save dialog. importantly ability set path & filename own variables. purpose or sake of example. insert "hello world" output.

exempli gratia:

echo hello world > %variable.path%%variable.file% 

the example below direct quote linked post.

:: chooser.bat :: launches file... open sort of file chooser , outputs choice console  @echo off setlocal enabledelayedexpansion  :: powershell.exe exist within %path%? %%i in (powershell.exe) 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 , link c# application open file browser dialog set chooser=%temp%\chooser.exe >"%temp%\c.cs" echo using system;using system.windows.forms; >>"%temp%\c.cs" echo class dummy{ >>"%temp%\c.cs" echo public static void main^(^){ >>"%temp%\c.cs" echo openfiledialog f=new openfiledialog^(^); >>"%temp%\c.cs" echo f.initialdirectory=environment.currentdirectory; >>"%temp%\c.cs" echo f.filter="text files (*.txt)|*.txt|all files (*.*)|*.*"; >>"%temp%\c.cs" echo f.showhelp=true; >>"%temp%\c.cs" echo f.showdialog^(^); >>"%temp%\c.cs" echo console.write^(f.filename^);}} /f "delims=" %%i in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') (     if not exist "!chooser!" "%%i" /nologo /out:"!chooser!" "%temp%\c.cs" 2>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 variable /f "delims=" %%i in ('%chooser%') set "filename=%%i"  echo chose %filename%  :: clean mess del "%temp%\chooser.exe" 2>nul     goto :eof 

enter image description here

i have tried adapt above example work save as. don't understand enough so. why i'm using batch scripts , not higher functioning programming language in first place.

my understanding of above is windows batch script invokes either powershell, if exists or if powershell doesn't exist .net if exists. have use existing code alternative if neither exist. alternative has user input full path manually.

echo set path file: echo path , file cannot contain spaces. e.g. c:\folder_name\file.ext echo sure include filename. set /p path1=">"? cls echo path set to: %path1% pause cls goto :eof 

i have asked on existing post. not permissible in site rules. asked separately. or insight welcome.

thank time & effort.

here example using windows forms (savefiledialog class).

rq : don't need button creating new directory, because can right click on file panel so.

clear-host add-type -assemblyname system.windows.forms $savefile = new-object system.windows.forms.savefiledialog  $savefile.filter = "all files (*.*)|*.*" $savefile.filterindex = 2 $savefile.restoredirectory = $true  $rc = $savefile.showdialog() if ($rc -eq [system.windows.forms.dialogresult]::ok) {   $savefile.filename   [system.windows.forms.messagebox]::show("you can save $($savefile.filename)", "ok") } 

be careful, message box, when it's ok, not appear on top of windows.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -