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"