我越来越疯狂,要做一些相对容易的事情... 我在使用bat文件中的代码File/folder chooser dialog from a Windows batch script来打开文件对话框并让用户选择多个文件。 接下来我需要做的是将单个字符串中的选择结果连接起来,作为参数传递给另一个应用程序。我无法在连接字符串...以1个字符串连接文件对话框的输出
我所拥有的是:
<# : 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
set slctn=
for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do (
echo You chose %%~I
set slctn=!slctn!|%%~I
)
REM here use %slctn% in another command
echo %slctn%
goto :EOF
: end Batch portion/begin PowerShell hybrid chimera #>
Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = "C:\Users\Public\Documents\MCI\Sito Web"
$f.Title = "Seleft PDF files to merge"
$f.Filter = "PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*"
$f.ShowHelp = $true
$f.Multiselect = $true
[void]$f.ShowDialog()
if ($f.Multiselect) { $f.FileNames } else { $f.FileName }
而结果我得到的是:
C:\Users\Public\Documents\MCI\Sito Web\Insieme>MergePDFInsieme
You chose C:\Users\Public\Documents\MCI\Sito Web\Ristorante\2016-02-08\menugiornaliero.pdf
'C:\Users\Public\Documents\MCI\Sito' is not recognized as an internal or external command, operable program or batch file.
C:\Users\Public\Documents\MCI\Sito Web\Insieme>
有人能帮忙吗?
另一种选择是显示所述值时,使用延迟扩展。但是OP应该知道变量的最大长度<8191字节。 – dbenham
谢谢你,几乎完美...现在我不再有错误,但变量读数不能按预期工作,我得到'C:\ Users \ Public \ Documents \ MCI \ Sito Web \ Insieme> MergePDFInsieme.cmd 您选择了C:\ Users \ Public \ Documents \ MCI \ Sito Web \ Ristorante \ 2016-02 C:\ Users \ Public \ Documents \ MCI \ Sito Web \ Ristorante \ 2016-02-15 \ menugiornaliero.pdf -15 \ specialitasettimana.pdf “!slctn!| C:\ Users \ Public \ Documents \ MCI \ Sito Web \ Ristorante \ 2016-02-15 \ specialitasettimana.pdf”' – rodedo
通过添加“EnableDelayedExpansion” 。 – rodedo