0

I am having some issues with modifiying a Powershell/batch hybrid script taken from another stack overflow question (https://stackoverflow.com/a/15885133/1683264).

When selecting a file and echoing the command line parameter with quotation marks it works fine if the file name and path are short, however when the length is longer than the cmd window it will split it into two lines.

I think that this has something to do with using a command line parameter vs using a variable, however I am very new to both batch script and powershell and I'd appreciate any help!

<# : 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 "%%~I"



)
pause
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 = "DAT Files (*.dat*)|*.dat*|All Files (*.*)|*.*"
$f.ShowHelp = $true
$f.Multiselect = $true
[void]$f.ShowDialog()
if ($f.Multiselect) {$f.FileNames} else {$f.FileName}

I am looking for the output to be

"fullnameandpath.dat" 

however if I have a long path and file name I get something like this:

"fullnamea"
"
"ndpath.dat"
  • What is the type of `$f.FileNames` and `$f.FileName`? Are these and array of strings and a string respectively? Is there a requirement for a hybrid script? – lit Mar 28 '19 at 17:20
  • Hey @lit as far as I can tell from the .NET documentation FileNames and FileName should be an array of strings and a string respectively. [link] (https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.filedialog.filename?view=netframework-4.7.2#System_Windows_Forms_FileDialog_FileName) – StackExchanger Mar 28 '19 at 21:33

0 Answers0